GoodERP
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.

108 lines
4.2KB

  1. # Copyright 2016 上海开阖软件有限公司 (http://www.osbzr.com)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import models, fields, api
  4. class VoucherTemplate(models.Model):
  5. _name = 'voucher.template'
  6. _description = '凭证模板'
  7. name = fields.Char('模板名称', required=True)
  8. line_ids = fields.One2many(
  9. 'voucher.template.line', 'template_id', string='模板行')
  10. company_id = fields.Many2one(
  11. 'res.company',
  12. string='公司',
  13. change_default=True,
  14. default=lambda self: self.env.company)
  15. class VoucherTemplateLine(models.Model):
  16. _name = 'voucher.template.line'
  17. _description = '凭证模板明细'
  18. name = fields.Char('摘要')
  19. account_id = fields.Many2one('finance.account', '会计科目')
  20. partner_id = fields.Many2one('partner', '往来单位')
  21. goods_id = fields.Many2one('goods', '商品')
  22. template_id = fields.Many2one('voucher.template', string='模板id')
  23. auxiliary_id = fields.Many2one(
  24. 'auxiliary.financing', '辅助核算', help='辅助核算是对账务处理的一种补充,即实现更广泛的账务处理,\
  25. 以适应企业管理和决策的需要.辅助核算一般通过核算项目来实现', ondelete='restrict')
  26. company_id = fields.Many2one(
  27. 'res.company',
  28. string='公司',
  29. change_default=True,
  30. default=lambda self: self.env.company)
  31. @api.onchange('account_id')
  32. def onchange_account_id(self):
  33. res = {
  34. 'domain': {
  35. 'partner_id': [('name', '=', False)],
  36. 'goods_id': [('name', '=', False)],
  37. 'auxiliary_id': [('name', '=', False)]}}
  38. if not self.account_id or not self.account_id.auxiliary_financing:
  39. return res
  40. if self.account_id.auxiliary_financing == 'customer':
  41. res['domain']['partner_id'] = [('c_category_id', '!=', False)]
  42. elif self.account_id.auxiliary_financing == 'supplier':
  43. res['domain']['partner_id'] = [('s_category_id', '!=', False)]
  44. elif self.account_id.auxiliary_financing == 'goods':
  45. res['domain']['goods_id'] = []
  46. else:
  47. res['domain']['auxiliary_id'] = [
  48. ('type', '=', self.account_id.auxiliary_financing)]
  49. return res
  50. class VoucherTemplateWizard(models.TransientModel):
  51. _name = 'voucher.template.wizard'
  52. _description = '凭证模板生成向导'
  53. name = fields.Char(string='模板名称')
  54. is_change_old_template = fields.Boolean('修改原有模板')
  55. old_template_id = fields.Many2one('voucher.template', string='旧模板')
  56. voucher_id = fields.Many2one(
  57. 'voucher', '凭证id',
  58. default=lambda self: self.env.context.get('active_id'))
  59. company_id = fields.Many2one(
  60. 'res.company',
  61. string='公司',
  62. change_default=True,
  63. default=lambda self: self.env.company)
  64. def save_as_template(self):
  65. template_obj = self.env['voucher.template']
  66. template_line_lsit_dict = [[0, False, {
  67. 'name': voucher_line.name,
  68. 'account_id': voucher_line.account_id.id,
  69. 'partner_id': voucher_line.partner_id.id,
  70. 'goods_id': voucher_line.goods_id.id,
  71. 'auxiliary_id': voucher_line.auxiliary_id.id}] for voucher_line in
  72. self.voucher_id.line_ids]
  73. if self.is_change_old_template:
  74. self.old_template_id.line_ids = False
  75. self.old_template_id.write({'line_ids': template_line_lsit_dict})
  76. else:
  77. template_obj.create(
  78. {'name': self.name, 'line_ids': template_line_lsit_dict})
  79. class Voucher(models.Model):
  80. _inherit = 'voucher'
  81. template_id = fields.Many2one('voucher.template', string='模板')
  82. @api.onchange('template_id')
  83. def onchange_template_id(self):
  84. template_line_lsit_dict = [(0, 0, {
  85. 'name': line.name,
  86. 'account_id': line.account_id.id,
  87. 'partner_id': line.partner_id.id,
  88. 'auxiliary_id': line.auxiliary_id.id,
  89. 'goods_id': line.goods_id.id})
  90. for line in self.template_id.line_ids]
  91. self.line_ids = False
  92. return {'value': {'line_ids': template_line_lsit_dict}}
上海开阖软件有限公司 沪ICP备12045867号-1