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.

45 lines
1.4 KiB

4 years ago
  1. # Copyright 2020 Coop IT Easy SCRL fs
  2. # Robin Keunen <robin@coopiteasy.be>
  3. # Vincent Van Rossem <vincent@coopiteasy.be>
  4. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  5. from odoo import SUPERUSER_ID, api, fields, models
  6. class PurchaseOrder(models.Model):
  7. _inherit = "purchase.order"
  8. original_cpo_id = fields.Many2one(
  9. "purchase.order.generator",
  10. string="Original POG",
  11. help="POG used to generate this Purchase Order",
  12. )
  13. class PurchaseOrderLine(models.Model):
  14. _inherit = "purchase.order.line"
  15. @api.multi
  16. def compute_taxes_id(self):
  17. for pol in self:
  18. if self.env.uid == SUPERUSER_ID:
  19. company_id = self.env.user.company_id.id
  20. else:
  21. company_id = self.company_id.id
  22. fpos_id = (
  23. self.env["account.fiscal.position"]
  24. .with_context(company_id=company_id)
  25. .get_fiscal_position(pol.partner_id.id)
  26. )
  27. fpos = self.env["account.fiscal.position"].browse(fpos_id)
  28. pol.order_id.fiscal_position_id = fpos
  29. taxes = self.product_id.supplier_taxes_id
  30. taxes_id = fpos.map_tax(taxes) if fpos else taxes
  31. if taxes_id:
  32. taxes_id = taxes_id.filtered(
  33. lambda t: t.company_id.id == company_id
  34. )
  35. pol.taxes_id = taxes_id