accstock_report.py
6.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# from openerp.osv import osv, fields
from odoo import api, models
from odoo.exceptions import UserError, ValidationError
from datetime import datetime
# from openerp.tools.float_utils import float_round as round
class AccStockReport(models.AbstractModel):
_name = 'report.acct_stock.acct_report_stock'
def rmb_upper(self, value):
map = [u"零",u"壹",u"贰",u"叁",u"肆",u"伍",u"陆",u"柒",u"捌",u"玖"]
unit = [u"分",u"角",u"元",u"拾",u"佰",u"仟",u"万",u"拾",u"佰",u"仟",u"亿",u"拾",u"佰",u"仟",u"万",u"拾",u"佰",u"仟",u"兆"]
nums = [] #取出每一位数字,整数用字符方式转换避大数出现误差
for i in range(len(unit)-3, -3, -1):
if value >= 10**i or i < 1:
nums.append(int(round(value/(10**i),2))%10)
words = []
zflag = 0 #标记连续0次数,以删除万字,或适时插入零字
start = len(nums)-3
for i in range(start, -3, -1): #使i对应实际位数,负数为角分
if 0 != nums[start-i] or len(words) == 0:
if zflag:
words.append(map[0])
zflag = 0
words.append(map[nums[start-i]])
words.append(unit[i+2])
elif 0 == i or (0 == i%4 and zflag < 3): #控制‘万/元’
words.append(unit[i+2])
zflag = 0
else:
zflag += 1
if words[-1] != unit[0]: #结尾非‘分’补整字
words.append(u"整")
return ''.join(words)
# def _get_total(self,docids,data=None):
# quotation = self.env['acc.quotation']
# res = {}
# # a = {}
# for acc_quotation in quotation.browse(docids):
# amount_total = acc_quotation.amount_total or 0.00
# amount_total = round(amount_total,2)
# upper_amount = self.rmb_upper(amount_total)
# # a = {'upper_amount':upper_amount or 0,'amount_total':amount_total or 0}
# # res[purchase_model.id] = {'upper_amount':upper_amount or 0,'amount_total':amount_total or 0}
# res = {
# 'amount_total':amount_total,
# 'upper_amount':upper_amount
# }
# return res
def _get_logo(self,docids,data=None):
# company_id = self.env.user.company_id
stock = self.env['stock.picking'].browse(docids)
so_obj = self.env['sale.order'].search([('name', '=', stock.origin)])
if so_obj:
company_id = so_obj.sale_company
logo = company_id.logo
logo_transfer = str(logo, encoding="UTF8")
else:
raise ValidationError('未找到源销售单.')
return logo_transfer
def _get_order(self,docids,data=None):
stock = self.env['stock.picking'].browse(docids)
so_obj = self.env['sale.order'].search([('name', '=', stock.origin)])
if so_obj:
return so_obj
else:
raise ValidationError('未找到源销售单.')
def _get_today(self,docids,data=None):
forcast_date = datetime.now().date()
# quotation = self.env['acc.quotation'].browse(docids)
# company_id = quotation.sale_company
# qr_code = company_id.qr_code
# qr_transfer = str(qr_code, encoding="UTF8")
# # print (logo_transfer)
return forcast_date
def _get_partner_info(self,docids,data=None):
stock = self.env['stock.picking'].browse(docids)
so_obj = self.env['sale.order'].search([('name', '=', stock.origin)])
now_date = datetime.now().date()
partner = self.env['res.partner'].browse(so_obj.partner_id.id)
# try:
# address = partner.country_id.name + partner.state_id.name + partner.city + partner.street
# except Exception as e:
# address = ''
# address = partner.country_id.name + partner.state_id.name + partner.city + partner.street
res_partner_bank = self.env['res.partner.bank'].search([('partner_id','=',partner.id)])
if res_partner_bank:
for line in res_partner_bank:
bank_name = line.bank_id.name
bank_number = line.acc_number
else:
bank_name = ''
bank_number = ''
res = {
'now_date':now_date,
# 'address':address,
'bank_name':bank_name,
'bank_number':bank_number
}
return res
@api.model
def _get_report_values(self,docids,data=None):
report_obj = self.env['ir.actions.report']
report = report_obj._get_report_from_name('acct_stock.acct_report_stock')
now_date = self._get_today(docids)
so_obj = self._get_order(docids)
partner_info = self._get_partner_info(docids)
logo_transfer = self._get_logo(docids)
# qr_transfer = self._get_qrcode(docids)
# partner_info = self._get_partner_info(docids)
return {
'doc_ids': report.ids,
'doc_model': report.model,
'docs': self.env[report.model].browse(docids),
# 'total':ac,
'logo':logo_transfer,
'now_date':now_date,
'so_obj':so_obj,
'partner_info':partner_info,
'report_type': data.get('report_type') if data else '',
}