|
- # Copyright 2016 上海开阖软件有限公司 (http://www.osbzr.com)
- # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-
- from odoo import models, fields, api
-
-
- class VoucherTemplate(models.Model):
- _name = 'voucher.template'
- _description = '凭证模板'
-
- name = fields.Char('模板名称', required=True)
- line_ids = fields.One2many(
- 'voucher.template.line', 'template_id', string='模板行')
- company_id = fields.Many2one(
- 'res.company',
- string='公司',
- change_default=True,
- default=lambda self: self.env.company)
-
-
- class VoucherTemplateLine(models.Model):
- _name = 'voucher.template.line'
- _description = '凭证模板明细'
-
- name = fields.Char('摘要')
- account_id = fields.Many2one('finance.account', '会计科目')
- partner_id = fields.Many2one('partner', '往来单位')
- goods_id = fields.Many2one('goods', '商品')
- template_id = fields.Many2one('voucher.template', string='模板id')
- auxiliary_id = fields.Many2one(
- 'auxiliary.financing', '辅助核算', help='辅助核算是对账务处理的一种补充,即实现更广泛的账务处理,\
- 以适应企业管理和决策的需要.辅助核算一般通过核算项目来实现', ondelete='restrict')
- company_id = fields.Many2one(
- 'res.company',
- string='公司',
- change_default=True,
- default=lambda self: self.env.company)
-
- @api.onchange('account_id')
- def onchange_account_id(self):
- res = {
- 'domain': {
- 'partner_id': [('name', '=', False)],
- 'goods_id': [('name', '=', False)],
- 'auxiliary_id': [('name', '=', False)]}}
- if not self.account_id or not self.account_id.auxiliary_financing:
- return res
- if self.account_id.auxiliary_financing == 'customer':
- res['domain']['partner_id'] = [('c_category_id', '!=', False)]
- elif self.account_id.auxiliary_financing == 'supplier':
- res['domain']['partner_id'] = [('s_category_id', '!=', False)]
- elif self.account_id.auxiliary_financing == 'goods':
- res['domain']['goods_id'] = []
- else:
- res['domain']['auxiliary_id'] = [
- ('type', '=', self.account_id.auxiliary_financing)]
- return res
-
-
- class VoucherTemplateWizard(models.TransientModel):
- _name = 'voucher.template.wizard'
- _description = '凭证模板生成向导'
-
- name = fields.Char(string='模板名称')
- is_change_old_template = fields.Boolean('修改原有模板')
- old_template_id = fields.Many2one('voucher.template', string='旧模板')
- voucher_id = fields.Many2one(
- 'voucher', '凭证id',
- default=lambda self: self.env.context.get('active_id'))
- company_id = fields.Many2one(
- 'res.company',
- string='公司',
- change_default=True,
- default=lambda self: self.env.company)
-
- def save_as_template(self):
- template_obj = self.env['voucher.template']
- template_line_lsit_dict = [[0, False, {
- 'name': voucher_line.name,
- 'account_id': voucher_line.account_id.id,
- 'partner_id': voucher_line.partner_id.id,
- 'goods_id': voucher_line.goods_id.id,
- 'auxiliary_id': voucher_line.auxiliary_id.id}] for voucher_line in
- self.voucher_id.line_ids]
- if self.is_change_old_template:
- self.old_template_id.line_ids = False
- self.old_template_id.write({'line_ids': template_line_lsit_dict})
- else:
- template_obj.create(
- {'name': self.name, 'line_ids': template_line_lsit_dict})
-
-
- class Voucher(models.Model):
- _inherit = 'voucher'
- template_id = fields.Many2one('voucher.template', string='模板')
-
- @api.onchange('template_id')
- def onchange_template_id(self):
- template_line_lsit_dict = [(0, 0, {
- 'name': line.name,
- 'account_id': line.account_id.id,
- 'partner_id': line.partner_id.id,
- 'auxiliary_id': line.auxiliary_id.id,
- 'goods_id': line.goods_id.id})
- for line in self.template_id.line_ids]
- self.line_ids = False
- return {'value': {'line_ids': template_line_lsit_dict}}
|