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.

46 lines
1.5 KiB

  1. # Copyright 2019 Tecnativa - Ernesto Tejeda
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo import api, fields, models
  4. import odoo.addons.decimal_precision as dp
  5. class ProductPack(models.Model):
  6. _inherit = 'product.pack.line'
  7. @api.multi
  8. def get_sale_order_line_vals(self, line, order):
  9. self.ensure_one()
  10. vals = super().get_sale_order_line_vals(line, order)
  11. quantity = self.quantity * line.product_uom_qty
  12. line_vals = {
  13. 'order_id': order.id,
  14. 'product_id': self.product_id.id or False,
  15. 'pack_parent_line_id': line.id,
  16. 'pack_depth': line.pack_depth + 1,
  17. 'company_id': order.company_id.id,
  18. }
  19. sol = line.new(line_vals)
  20. sol.product_id_change()
  21. sol.product_uom_qty = quantity
  22. sol.product_uom_change()
  23. sol._onchange_discount()
  24. vals = sol._convert_to_write(sol._cache)
  25. sale_discount = 0.0
  26. if (line.product_id.pack_component_price == 'detailed'):
  27. sale_discount = 100.0 - (
  28. (100.0 - sol.discount) * (100.0 - self.sale_discount) / 100.0)
  29. vals.update({
  30. 'discount': sale_discount,
  31. 'name': '%s%s' % (
  32. '> ' * (line.pack_depth + 1), sol.name
  33. ),
  34. })
  35. return vals
  36. @api.multi
  37. def get_price(self):
  38. self.ensure_one()
  39. return super().get_price() * (1 - self.sale_discount / 100.0)