You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

572 lines
27KB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Copyright (C) 2016 德清武康开源软件().
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as
  8. # published by the Free Software Foundaption, either version 3 of the
  9. # License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. ##############################################################################
  20. from odoo import api, fields, models, tools, _
  21. import odoo.addons.decimal_precision as dp
  22. import datetime
  23. import re
  24. from odoo.exceptions import UserError
  25. import xlrd
  26. import base64
  27. import os
  28. import odoo
  29. class cn_account_invoice(models.Model):
  30. _name = 'cn.account.invoice'
  31. _description = '中国发票'
  32. _rec_name= 'name'
  33. _inherit = ['mail.thread']
  34. partner_name_in = fields.Char('供应商名称', copy=False)
  35. partner_code_in = fields.Char('供应商税号', copy=False)
  36. partner_address_in = fields.Char('供应商地址及电话', copy=False)
  37. partner_bank_number_in = fields.Char('供应商银行及帐号', copy=False)
  38. partner_name_out = fields.Char('客户名称', copy=False)
  39. partner_code_out = fields.Char('客户税号', copy=False)
  40. partner_address_out = fields.Char('客户地址及电话', copy=False)
  41. partner_bank_number_out = fields.Char('客户银行及帐号', copy=False)
  42. type = fields.Selection([('in', '进项发票'),
  43. ('out', '销项发票'),
  44. ('all', '内部发票')], '进/出发票', copy=False)
  45. invoice_type = fields.Many2one('cn.invoice.type', '发票类型', copy=False)
  46. use_heck_code = fields.Boolean('是否需要检验码')
  47. is_export = fields.Boolean('是否出口退税')
  48. invoice_code = fields.Char('发票代码', copy=False)
  49. name = fields.Char('发票号码', copy=False, index=True)
  50. invoice_export_amount = fields.Float('外币', copy=False)
  51. invoice_amount = fields.Float('金额', copy=False)
  52. invoice_tax = fields.Float('税额', copy=False)
  53. invoice_heck_code = fields.Char("发票校验码", copy=False)
  54. invoice_date = fields.Date('开票日期', copy=False)
  55. tax_rate = fields.Float('税率', compute='_compute_tax_rate',digits=(12, 0), store=True)
  56. is_deductible = fields.Boolean('是否抵扣')
  57. line_ids = fields.One2many('cn.account.invoice.line', 'order_id', '发票明细行',
  58. copy=False)
  59. line_ids2 = fields.One2many('cn.account.invoice.line', 'order_id', '发票明细行',
  60. copy=False)
  61. attachment_number = fields.Integer(compute='_compute_attachment_number', string='附件号')
  62. note = fields.Text("备注")
  63. color = fields.Integer('颜色', related='invoice_type.color')
  64. line_type = fields.Selection([('same', '一般发票'),
  65. ('transport', '运输'),], string='明细类型', copy=False, index=True, readonly=True, default='same')
  66. company_id_in = fields.Many2one('res.company', string='关联公司进')
  67. company_id_out = fields.Many2one('res.company', string='关联公司销')
  68. _sql_constraints = [
  69. ('unique_invoice_code_name', 'unique (invoice_code, name)', '发票代码+发票号码不能相同!'),
  70. ]
  71. def _get_full_excel_template_path(self, template_path):
  72. for path in odoo.addons.__path__:
  73. if os.path.exists(path + template_path):
  74. return path + template_path
  75. return False
  76. @api.depends('invoice_amount', 'invoice_tax', 'is_deductible')
  77. def _compute_tax_rate(selfs):
  78. for self in selfs:
  79. if not self.is_deductible:
  80. self.tax_rate = 0
  81. else:
  82. self.tax_rate = int(self.invoice_tax / self.invoice_amount * 100)
  83. @api.onchange('invoice_type')
  84. def _use_heck_code(self):
  85. for order in self:
  86. if order.invoice_type and order.invoice_type.code in ['pp', 'dzfp']:
  87. order.use_heck_code = True
  88. else:
  89. order.use_heck_code = False
  90. def action_get_attachment_view(self):
  91. res = self.env['ir.actions.act_window']._for_xml_id('base.action_attachment')
  92. res['domain'] = [('res_model', '=', 'cn.account.invoice'), ('res_id', 'in', self.ids)]
  93. res['context'] = {'default_res_model': 'cn.account.invoice', 'default_res_id': self.id}
  94. return res
  95. def _compute_attachment_number(self):
  96. attachment_data = self.env['ir.attachment'].read_group(
  97. [('res_model', '=', 'cn.account.invoice'), ('res_id', 'in', self.ids)], ['res_id'], ['res_id'])
  98. attachment = dict((data['res_id'], data['res_id_count']) for data in attachment_data)
  99. for expense in self:
  100. expense.attachment_number = attachment.get(expense.id, 0)
  101. def create_uom(self):
  102. for mx in self.line_ids:
  103. uom = mx.product_unit
  104. if uom:
  105. uom_id = self.env['uom'].search([('name', '=', uom)])
  106. if not uom_id:
  107. uom_id = self.env['uom'].create({
  108. 'name': uom,
  109. 'active': 1})
  110. def create_category(self):
  111. for mx in self.line_ids:
  112. category = mx.tax_type
  113. if category:
  114. category_id = self.env['core.category'].search([
  115. '&', ('type', '=', 'goods'), ('tax_category_id.print_name', '=', category)])
  116. if not category_id:
  117. if self.type == 'in':
  118. account_id = self.env['ir.values'].get_default('tax.config.settings', 'default_buy_goods_account')
  119. if self.type == 'out':
  120. account_id = self.env['ir.values'].get_default('tax.config.settings',
  121. 'default_sell_goods_account')
  122. category_id = self.env['core.category'].create({
  123. 'type': 'goods',
  124. 'name': category,
  125. 'account_id': account_id,
  126. 'tax_category_id': self.env['tax.category'].search([('print_name', '=', category)],limit=1).id,
  127. 'note': '由系统自动增加'
  128. })
  129. def create_product(self):
  130. for mx in self.line_ids:
  131. goods = mx.product_name
  132. uom = mx.product_unit
  133. uom_id = self.env['uom'].search([('name', '=', uom)])
  134. category = mx.tax_type
  135. category_id = self.env['core.category'].search([
  136. '&', ('type', '=', 'goods'), ('tax_category_id.print_name', '=', category)])
  137. if category_id and category_id.tax_category_id.code[0] == '1':
  138. no_stock = False
  139. else:
  140. no_stock = True
  141. if goods:
  142. goods_id = self.env['goods'].search([('name', '=', goods)])
  143. if not goods_id:
  144. self.env['goods'].create({
  145. 'name': goods,
  146. 'uom_id': uom_id.id or '',
  147. 'uos_id': uom_id.id or '',
  148. # 'tax_rate': float(in_xls_data.get('税率')),
  149. 'category_id': category_id and category_id.id,
  150. 'computer_import': True,
  151. 'no_stock': no_stock,
  152. 'cost_method': 'average',
  153. })
  154. # 创建供应商
  155. def create_buy_partner(self):
  156. if self.partner_code_in:
  157. partner_id = self.env['partner'].search([
  158. ('tax_num', '=', self.partner_code_in)])
  159. if self.partner_name_in:
  160. partner_id = self.env['partner'].search([
  161. ('name', '=', self.partner_name_in)])
  162. default_goods_supplier = self.env['ir.values'].get_default('tax.config.settings', 'default_goods_supplier')
  163. if not default_goods_supplier:
  164. raise UserError('请设置默认产品供应商!')
  165. if not partner_id:
  166. partner_id = self.env['partner'].create({
  167. 'name': self.partner_name_in,
  168. 'main_mobile': self.partner_code_in,
  169. 'tax_num': self.partner_code_in,
  170. 's_category_id': default_goods_supplier,
  171. 'computer_import': True,
  172. })
  173. # 补银行帐号等信息
  174. if self.partner_address_in and partner_id.main_mobile == partner_id.tax_num:
  175. main_mobile = self.split_number(self.partner_address_in)
  176. partner_id.write({'main_mobile': main_mobile})
  177. if self.partner_address_in and not partner_id.main_address:
  178. if partner_id.main_mobile and partner_id.main_mobile != partner_id.tax_num:
  179. to_del_mobile = len(partner_id.main_mobile)
  180. else:
  181. to_del_mobile = 0
  182. main_address = self.partner_address_in[:-to_del_mobile]
  183. partner_id.write({'main_address': main_address})
  184. if self.partner_bank_number_in and not partner_id.bank_num:
  185. bank_number = self.split_number(self.partner_bank_number_in)
  186. partner_id.write({'bank_num': bank_number})
  187. if self.partner_bank_number_in and not (partner_id.bank_num or partner_id.bank_name):
  188. if self.bank_num:
  189. to_del_bank_number = len(self.bank_num)
  190. else:
  191. to_del_bank_number = 0
  192. bank_name = self.partner_bank_number_in[:-to_del_bank_number]
  193. partner_id.write({'bank_name': bank_name})
  194. # 创建客户
  195. def create_sell_partner(self):
  196. if self.partner_code_out:
  197. partner_id = self.env['partner'].search([
  198. ('tax_num', '=', self.partner_code_out)])
  199. elif self.partner_name_out:
  200. partner_id = self.env['partner'].search([
  201. ('name', '=', self.partner_name_out)])
  202. default_customer = self.env['ir.values'].get_default('tax.config.settings', 'default_customer')
  203. if not default_customer:
  204. raise UserError('请设置默认产品供应商!')
  205. if not partner_id:
  206. partner_id = self.env['partner'].create({
  207. 'name': self.partner_name_out,
  208. 'main_mobile': self.partner_code_out,
  209. 'tax_num': self.partner_code_out,
  210. 'c_category_id':default_customer,
  211. 'computer_import': True,
  212. })
  213. # 补银行帐号等信息
  214. if self.partner_address_out and partner_id.main_mobile == partner_id.tax_num:
  215. main_mobile = self.split_number(self.partner_address_out)
  216. partner_id.write({'main_mobile': main_mobile})
  217. if self.partner_address_out and not partner_id.main_address:
  218. if partner_id.main_mobile and partner_id.main_mobile != partner_id.tax_num:
  219. to_del_mobile = len(partner_id.main_mobile)
  220. else:
  221. to_del_mobile = 0
  222. main_address = self.partner_address_out[:-to_del_mobile]
  223. partner_id.write({'main_address': main_address})
  224. if self.partner_bank_number_out and not partner_id.bank_num:
  225. bank_number = self.split_number(self.partner_bank_number_out)
  226. partner_id.write({'bank_num': bank_number})
  227. if self.partner_bank_number_out and not partner_id.bank_name:
  228. if partner_id.bank_num:
  229. to_del_bank_number = len(partner_id.bank_num)
  230. else:
  231. to_del_bank_number = 0
  232. bank_name = self.partner_bank_number_out[:-to_del_bank_number]
  233. partner_id.write({'bank_name': bank_name})
  234. # 跟据帐号和电话都在后面的特性,使用倒转后从头直至有字母出现为此都是帐号和电话。
  235. def split_number(self, str):
  236. str1 = str[::-1] #
  237. changdu = len(str1) # 取长度
  238. num = ''
  239. i = 0
  240. while i < changdu:
  241. if str1[i].isdigit() or str1[i] == '-' or str1[i] == ' ':
  242. num += str1[i]
  243. i += 1
  244. else:
  245. return num[::-1]
  246. #定义发票明细行
  247. class cn_account_invoice_line(models.Model):
  248. _name = 'cn.account.invoice.line'
  249. _description = '中国发票明细'
  250. _rec_name='product_name'
  251. order_id = fields.Many2one('cn.account.invoice', '发票',help='关联发票',copy=False, required=True,
  252. readonly=True, index=True, ondelete="cascade",)
  253. product_name = fields.Char("货物名称",copy=False)
  254. product_type = fields.Char("规格型号",copy=False)
  255. product_unit = fields.Char("单位",copy=False)
  256. product_count = fields.Float("数量",copy=False)
  257. product_price = fields.Float("价格",copy=False)
  258. product_amount = fields.Float("金额",copy=False)
  259. product_tax_rate = fields.Integer("税率",copy=False)
  260. product_tax = fields.Float("税额",copy=False)
  261. tax_type = fields.Char('税收分类编码',help='20170101以后使用的税收分类编码,这个很重要',copy=False)
  262. note = fields.Char("备注",copy=False)
  263. car_number = fields.Char("车牌号", copy=False)
  264. car_type = fields.Char("类型", copy=False)
  265. car_begin_date = fields.Char("通行日期起", copy=False)
  266. car_end_date = fields.Char("通行日期止", copy=False)
  267. class create_cn_invoice_wizard(models.TransientModel):
  268. _name = 'create.cn.invoice.wizard'
  269. _description = '导入发票'
  270. excel = fields.Binary(u'导入认证系统导出的excel文件',)
  271. type = fields.Selection([('in', '进项发票'),
  272. ('out', '销项发票'),], '进/出发票', copy=False)
  273. company_id = fields.Many2one(
  274. 'res.company',
  275. string='公司',
  276. change_default=True)
  277. def create_tax_invoice(self):
  278. not_input, is_input = self.create_invoice()
  279. self.create_invoice_line(not_input)
  280. return {
  281. 'name': _('导入发票'),
  282. 'view_mode': 'tree,form',
  283. 'domain': [('id', 'in', is_input)],
  284. 'res_model': 'cn.account.invoice',
  285. 'type': 'ir.actions.act_window',
  286. 'context': {'create': False, 'active_test': False},
  287. }
  288. def create_invoice_line(self,not_input):
  289. xls_data = xlrd.open_workbook(file_contents=base64.decodebytes(self.excel))
  290. all = xls_data.sheet_by_name('货物清单')
  291. ncows = all.nrows
  292. ncols = 0
  293. colnames = all.row_values(0)
  294. list = []
  295. for rownum in range(1, ncows):
  296. row = all.row_values(rownum)
  297. if row:
  298. app = {}
  299. for i in range(len(colnames)):
  300. app[colnames[i]] = row[i]
  301. list.append(app)
  302. ncols += 1
  303. in_xls_data = {}
  304. for data in range(0, ncols):
  305. in_xls_data = list[data]
  306. product_name = in_xls_data.get('货物或应税劳务名称') or in_xls_data.get('货物或应税劳务、服务名称')
  307. invoice_name = in_xls_data.get('发票号码') or in_xls_data.get('数电票号码')
  308. if product_name == "(详见销货清单)" or product_name == '详见对应正数发票及清单' or product_name == "(详见销货清单)":
  309. continue
  310. if str(invoice_name) in not_input:
  311. continue
  312. invoice_code = in_xls_data.get(u'发票代码')
  313. company_in_sys_invoice = self.env['cn.account.invoice'].search([
  314. ('invoice_code', '=', str(invoice_code)),
  315. ('name', '=', str(invoice_name)),
  316. ('type', '=', self.type)])
  317. amount = float(in_xls_data.get('金额'))
  318. tax = float(in_xls_data.get('税额'))
  319. tax_rate = 0
  320. if tax:
  321. tax_rate = round(tax / amount, 2) * 100
  322. if product_name:
  323. goods_name = product_name.split('*')[-1]
  324. if '*' in product_name:
  325. tax_type = product_name.split('*')[1]
  326. else:
  327. goods_name = product_name
  328. tax_type = ''
  329. if company_in_sys_invoice:
  330. self.env['cn.account.invoice.line'].create({
  331. 'order_id': company_in_sys_invoice.id,
  332. 'product_name': goods_name.strip() or '',
  333. 'product_type': in_xls_data.get('规格型号').strip() or '',
  334. 'product_unit': in_xls_data.get('单位').strip() or '',
  335. 'product_count': in_xls_data.get('数量') or '',
  336. 'product_price': in_xls_data.get('单价') or '',
  337. 'product_amount': amount or '0',
  338. 'product_tax_rate': tax_rate or '0',
  339. 'product_tax': tax or '0',
  340. 'tax_type': tax_type,
  341. })
  342. def create_invoice(self):
  343. not_input = is_input = []
  344. xls_data = xlrd.open_workbook(file_contents=base64.decodebytes(self.excel))
  345. all = xls_data.sheet_by_name('发票基础信息')
  346. ncows = all.nrows
  347. ncols = 0
  348. colnames = all.row_values(0)
  349. list = []
  350. # 数据读入,过滤没有发票状态的行
  351. for rownum in range(1, ncows):
  352. row = all.row_values(rownum)
  353. if row:
  354. app = {}
  355. for i in range(len(colnames)):
  356. app[colnames[i]] = row[i]
  357. if app['发票状态'] == '正常':
  358. list.append(app)
  359. ncols += 1
  360. for data in range(0, ncols-1):
  361. in_xls_data = list[data]
  362. code = ''
  363. if in_xls_data.get('数电票号码'):
  364. name = in_xls_data.get('数电票号码')
  365. else:
  366. name = in_xls_data.get('发票号码')
  367. code = in_xls_data.get('发票代码')
  368. if code:
  369. invoice_code = str(int(code)).zfill(len(code))
  370. else:
  371. invoice_code = ''
  372. if self.type == "in":
  373. partner_name = in_xls_data.get('销方名称')
  374. company_tax = in_xls_data.get('购方识别号')
  375. else:
  376. partner_name = in_xls_data.get('购方名称') or in_xls_data.get('购买方名称')
  377. company_tax = in_xls_data.get('销方识别号')
  378. if company_tax != self.company_id.vat:
  379. raise UserError('购买/销售方税号与公司税号不一致!请检查!%s,%s'%(company_tax, self.company_id.vat))
  380. invoice_name= str(int(name)).zfill(len(name))
  381. company_in_sys_invoice = self.env['cn.account.invoice'].search([
  382. ('invoice_code', '=', invoice_code),
  383. ('name', '=', invoice_name),
  384. ('type', '=', self.type)])
  385. amount = float(in_xls_data.get('金额'))
  386. tax = float(in_xls_data.get('税额'))
  387. if self.company_id and self.company_id.vat:
  388. if self.company_id.vat != company_tax:
  389. raise UserError('文件购买方税号为(%s)与公司税号(%s)不一致!'%(company_tax,self.company_id.vat))
  390. tax_rate = 0.0
  391. if tax:
  392. tax_rate = round(tax / amount,2) * 100
  393. invoice_type = self.env['cn.invoice.type'].search([('name', '=', in_xls_data.get('发票票种'))], limit=1)
  394. if not invoice_type:
  395. raise UserError('发票票种[%s]未找到!请到发票类型中增加'%(in_xls_data.get('发票票种')))
  396. if company_in_sys_invoice:
  397. not_input.append(invoice_name)
  398. continue
  399. else:
  400. note = in_xls_data.get(u'备注')
  401. if self.type == 'in':
  402. if amount > 0:
  403. is_deductible = invoice_type.is_coming_tax
  404. else:
  405. is_deductible = False
  406. invoice_id = self.env['cn.account.invoice'].create({
  407. 'type': self.type,
  408. 'partner_name_in': partner_name,
  409. 'partner_code_in': str(in_xls_data.get(u'销方识别号')),
  410. 'invoice_code': str(invoice_code),
  411. 'name': str(invoice_name),
  412. 'invoice_amount': amount,
  413. 'invoice_tax': tax,
  414. 'invoice_date': self.excel_date(in_xls_data.get(u'开票日期')),
  415. 'invoice_type': invoice_type.id,
  416. 'tax_rate': tax_rate,
  417. 'is_deductible': is_deductible,
  418. 'note': note,
  419. 'company_id_in': self.company_id.id,
  420. })
  421. else:
  422. invoice_id = self.env['cn.account.invoice'].create({
  423. 'type': self.type,
  424. 'partner_name_out': partner_name,
  425. 'partner_code_out': str(in_xls_data.get(u'购方识别号')),
  426. 'invoice_code': str(invoice_code),
  427. 'name': str(invoice_name),
  428. 'invoice_amount': amount,
  429. 'invoice_tax': tax,
  430. 'invoice_date': self.excel_date(in_xls_data.get(u'开票日期')),
  431. 'invoice_type': invoice_type.id,
  432. 'invoice_in_id': '',
  433. 'tax_rate': tax_rate,
  434. 'note': note,
  435. 'company_id_out': self.company_id.id,
  436. })
  437. is_out = re.findall('出口业务', in_xls_data.get(u'备注'))
  438. if is_out:
  439. for s in note.split(';'):
  440. invoice_export_amount = re.search(r'\d+(\.\d+)', s)
  441. invoice_id.write({
  442. 'is_export': True,
  443. 'invoice_export_amount': invoice_export_amount.group() or 0.0,
  444. })
  445. is_input.append(invoice_id.id)
  446. return not_input, is_input
  447. # def create_invoice2(self):
  448. # not_input = is_input = []
  449. # xls_data = xlrd.open_workbook(file_contents=base64.decodebytes(self.excel))
  450. # all = xls_data.sheets()[0]
  451. # ncows = all.nrows
  452. # ncols = 0
  453. # colnames = all.row_values(1)
  454. # list = []
  455. # top = all.row_values(0)
  456. # invoice_type = self.env['cn.invoice.type'].search([('name', '=', top[0])], limit=1)
  457. # # 数据读入,过滤没有开票日期的行
  458. # for rownum in range(2, ncows):
  459. # row = all.row_values(rownum)
  460. # if row:
  461. # app = {}
  462. # for i in range(len(colnames)):
  463. # app[colnames[i]] = row[i]
  464. # if app['发票状态'] == '正常':
  465. # list.append(app)
  466. # ncols += 1
  467. #
  468. # # 数据处理
  469. # in_xls_data = {}
  470. # for data in range(0, ncols):
  471. # in_xls_data = list[data]
  472. # invoice_code = str(int(in_xls_data.get('发票代码'))).zfill(len(in_xls_data.get('发票代码')))
  473. # if self.type == "in":
  474. # partner_name = in_xls_data.get('销售方名称')
  475. # company_tax = in_xls_data.get('购买方税号')
  476. # else:
  477. # partner_name = in_xls_data.get('购买方名称')
  478. # company_tax = in_xls_data.get('销售方税号')
  479. # if company_tax != self.company_id.vat:
  480. # raise UserError('购买/销售方税号与公司税号不一致!请检查!')
  481. # invoice_name= str(int(in_xls_data.get('发票号码'))).zfill(len(in_xls_data.get('发票号码')))
  482. # company_in_sys_invoice = self.env['cn.account.invoice'].search([
  483. # ('invoice_code', '=', invoice_code),
  484. # ('name', '=', invoice_name),
  485. # ('type', '=', self.type)])
  486. # amount = float(in_xls_data.get('金额'))
  487. # tax = float(in_xls_data.get('税额'))
  488. # if self.company_id and self.company_id.vat:
  489. # if self.company_id.vat != company_tax:
  490. # raise UserError('文件购买方税号为(%s)与公司税号(%s)不一致!'%(company_tax,self.company_id.vat))
  491. # tax_rate = 0.0
  492. # if tax:
  493. # tax_rate = round(tax / amount,2) * 100
  494. # if company_in_sys_invoice:
  495. # not_input.append(invoice_name)
  496. # continue
  497. # else:
  498. # note = in_xls_data.get(u'备注')
  499. # if self.type == 'in':
  500. # invoice_id = self.env['cn.account.invoice'].create({
  501. # 'type': self.type,
  502. # 'partner_name_in': partner_name,
  503. # 'partner_code_in': str(in_xls_data.get(u'销售方税号')),
  504. # 'invoice_code': str(invoice_code),
  505. # 'name': str(invoice_name),
  506. # 'invoice_amount': amount,
  507. # 'invoice_tax': tax,
  508. # 'invoice_date': self.excel_date(in_xls_data.get(u'开票日期')),
  509. # 'invoice_type': invoice_type.id,
  510. # 'tax_rate': tax_rate,
  511. # 'note': note,
  512. # })
  513. # else:
  514. # invoice_id = self.env['cn.account.invoice'].create({
  515. # 'type': self.type,
  516. # 'partner_name_out': partner_name,
  517. # 'partner_code_out': str(in_xls_data.get(u'购买方税号')),
  518. # 'invoice_code': str(invoice_code),
  519. # 'name': str(invoice_name),
  520. # 'invoice_amount': amount,
  521. # 'invoice_tax': tax,
  522. # 'invoice_date': self.excel_date(in_xls_data.get(u'开票日期')),
  523. # 'invoice_type': invoice_type.id,
  524. # 'invoice_in_id': '',
  525. # 'tax_rate': tax_rate,
  526. # 'note': note,
  527. # })
  528. # is_out = re.findall('出口业务', in_xls_data.get(u'备注'))
  529. # if is_out:
  530. # for s in note.split(';'):
  531. # invoice_export_amount = re.search(r'\d+(\.\d+)', s)
  532. # invoice_id.write({
  533. # 'is_export': True,
  534. # 'invoice_export_amount': invoice_export_amount.group() or 0.0,
  535. # })
  536. # is_input.append(invoice_id.id)
  537. # return not_input, is_input
  538. def excel_date(self, data):
  539. # 将excel日期改为正常日期
  540. if type(data) in (int, float):
  541. year, month, day, hour, minute, second = xlrd.xldate_as_tuple(data, 0)
  542. py_date = datetime.datetime(year, month, day, hour, minute, second)
  543. else:
  544. py_date = data
  545. return py_date
上海开阖软件有限公司 沪ICP备12045867号-1