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.

91 line
4.3KB

  1. # Copyright 2016 上海开阖软件有限公司 (http://www.osbzr.com)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import fields, models, api
  4. from odoo import exceptions
  5. class CostLine(models.Model):
  6. _name = 'cost.line'
  7. _description = "采购销售费用"
  8. @api.depends('amount', 'tax_rate')
  9. def _compute_tax(self):
  10. """
  11. 计算字段根据 amount 和 tax_rate 是否变化进行判定tax 是否需要重新计算
  12. :return:
  13. """
  14. for s in self:
  15. s.tax = s.amount * s.tax_rate * 0.01
  16. def _inverse_subtotal(self):
  17. """
  18. 计算字段根据 amount 和 tax_rate 是否变化进行判定tax 是否需要重新计算
  19. :return:
  20. """
  21. for s in self:
  22. s.amount = 100 * s.subtotal / (100 + s.tax_rate)
  23. partner_id = fields.Many2one('partner', '供应商', ondelete='restrict',
  24. required=True,
  25. help='采购/销售费用对应的业务伙伴')
  26. category_id = fields.Many2one('core.category', '类别',
  27. required=True,
  28. ondelete='restrict',
  29. domain=[('type', '=', 'expense')],
  30. help='分类:采购')
  31. amount = fields.Float('金额',
  32. required=True,
  33. digits='Amount',
  34. help='采购/销售费用金额')
  35. tax_rate = fields.Float(
  36. '税率(%)',
  37. default=lambda self: self.env.user.company_id.import_tax_rate,
  38. help='默认值取公司进项税率')
  39. tax = fields.Float('税额',
  40. digits='Amount',
  41. compute=_compute_tax, store=True,
  42. help='采购/销售费用税额')
  43. subtotal = fields.Float('价税合计', digits='Amount', compute='_compute_all_currency', inverse=_inverse_subtotal, store=True)
  44. note = fields.Char('备注',
  45. help='该采购/销售费用添加的一些标识信息')
  46. company_id = fields.Many2one(
  47. 'res.company',
  48. string='公司',
  49. change_default=True,
  50. default=lambda self: self.env.company)
  51. standard_amount = fields.Float('本位币金额', compute='_compute_all_currency',
  52. store=True, readonly=True,
  53. digits='总数',
  54. help='本位币的成交金额')
  55. currency_id = fields.Many2one('res.currency',
  56. '外币币别', store=True, compute='_compute_all_currency',
  57. help='外币币别')
  58. currency_rate = fields.Float('汇率', digits='Price', store=True, compute='_compute_all_currency')
  59. standard_subtotal = fields.Float('本位币价税合计', digits='Price', store=True, compute='_compute_all_currency')
  60. @api.onchange('partner_id', 'category_id')
  61. def _onchange_partner_id_category_id(self):
  62. err = ''
  63. for record in self:
  64. if record.partner_id and record.category_id:
  65. partner_c = record.partner_id.s_category_id.account_id.currency_id or self.env.company.currency_id
  66. category_c = record.category_id.account_id.currency_id or self.env.company.currency_id
  67. if partner_c != category_c:
  68. err += "采购费用行 供应商%s的币种%s 与类别币种%s不相同\n" % (
  69. record.partner_id.name, partner_c.name, category_c.name)
  70. if err:
  71. raise exceptions.ValidationError(err)
  72. @api.depends('category_id', 'amount', 'tax','tax_rate')
  73. def _compute_all_currency(self):
  74. for record in self:
  75. record.currency_id = record.category_id.account_id.currency_id or self.env.company.currency_id
  76. record.currency_rate = record.currency_id.rate
  77. record.standard_amount = record.amount * record.currency_rate
  78. record.subtotal = record.amount + record.tax
  79. record.standard_subtotal = record.subtotal * record.currency_id.rate
  80. # if (record.tax > 0 or record. tax_rate) and record.currency_id !=self.env.company.currency_id:
  81. # raise UserError('外币费用的税率只能为0')
上海开阖软件有限公司 沪ICP备12045867号-1