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.

66 lines
3.0 KiB

  1. # © 2020 Le Filament (<http://www.le-filament.com>)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo import _, api, fields, models
  4. from odoo.exceptions import ValidationError
  5. from odoo.addons import decimal_precision as dp
  6. class ProductTemplate(models.Model):
  7. _inherit = 'product.template'
  8. list_price_ref_pack = fields.Float(
  9. 'Prix référent au kilo', default=1.0,
  10. digits=dp.get_precision('Product Price'),
  11. compute='_compute_list_price_ref_pack')
  12. price_ref_pack_compute = fields.Float(
  13. 'Prix calculé', default=1.0,
  14. digits=dp.get_precision('Product Price'),
  15. compute='_compute_price_ref_pack_compute')
  16. def _compute_list_price_ref_pack(self):
  17. for template in self:
  18. if template.pack_line_ids:
  19. if template.pack_ok and (template.pack_type == 'detailed' and template.pack_component_price == 'totalized'):
  20. pack_price_ref = 0.0
  21. for pack_line in template.pack_line_ids:
  22. pack_price_ref += pack_line.product_id.list_price
  23. template.list_price_ref_pack = pack_price_ref
  24. def _compute_price_ref_pack_compute(self):
  25. for template in self:
  26. if template.pack_line_ids:
  27. if template.pack_ok and (template.pack_type == 'detailed' and template.pack_component_price == 'totalized'):
  28. pack_price = 0.0
  29. for pack_line in template.pack_line_ids:
  30. pack_price += pack_line.product_id.list_price * pack_line.quantity
  31. template.price_ref_pack_compute = pack_price
  32. @api.multi
  33. def website_publish_button(self):
  34. self.ensure_one()
  35. res = super(ProductTemplate, self).website_publish_button()
  36. # Dépublie les packs enfants si il en existe
  37. if self.used_in_pack_line_ids:
  38. for pack in self.used_in_pack_line_ids:
  39. pack.parent_product_id.write({'website_published': not self.website_published})
  40. return res
  41. @api.multi
  42. def get_info_parent_pack(self):
  43. for pack in self:
  44. if pack.pack_line_ids:
  45. if pack.pack_ok and (
  46. pack.pack_type == 'detailed' and pack.pack_component_price == 'totalized'):
  47. product_parent_id = pack.pack_line_ids[0].product_id
  48. pack.description_sale = product_parent_id.description_sale
  49. if product_parent_id.image:
  50. pack.write({
  51. 'image': product_parent_id.image,
  52. 'image_small': product_parent_id.image_small,
  53. 'image_medium': product_parent_id.image_medium,
  54. })
  55. if product_parent_id.product_image_ids:
  56. pack.write({
  57. 'product_image_ids': [(6, 0, product_parent_id.product_image_ids.ids)]
  58. })