|
| 1 | +############################################################################## |
| 2 | +# For copyright and license notices, see __manifest__.py file in module root |
| 3 | +# directory |
| 4 | +############################################################################## |
| 5 | +from odoo import api, fields, models |
| 6 | + |
| 7 | + |
| 8 | +class ProductPricelist(models.Model): |
| 9 | + _inherit = "product.pricelist" |
| 10 | + |
| 11 | + price = fields.Monetary( |
| 12 | + compute="_compute_price", |
| 13 | + help="Price for product specified on the context", |
| 14 | + ) |
| 15 | + show_products = fields.Boolean( |
| 16 | + "Show in products", |
| 17 | + default=True, |
| 18 | + help="By selecting it allows you to display the pricelist with the price of that product in the products", |
| 19 | + ) |
| 20 | + |
| 21 | + def _compute_price(self): |
| 22 | + self = self.sudo() |
| 23 | + active_id = model = False |
| 24 | + if "pricelist_product_id" in self.env.context: |
| 25 | + active_id = self.env.context.get("pricelist_product_id") |
| 26 | + model = "product.product" |
| 27 | + elif "pricelist_template_id" in self.env.context: |
| 28 | + active_id = self.env.context.get("pricelist_template_id") |
| 29 | + model = "product.template" |
| 30 | + else: |
| 31 | + self.price = 0.0 |
| 32 | + |
| 33 | + if active_id and model: |
| 34 | + product = self.env[model].browse(active_id) |
| 35 | + for rec in self: |
| 36 | + contextual_price = product.with_context(pricelist=rec.id)._get_contextual_price() |
| 37 | + rec.sudo().write({"price": contextual_price}) |
| 38 | + |
| 39 | + @api.model |
| 40 | + def _get_view(self, view_id=None, view_type="form", **options): |
| 41 | + arch, view = super()._get_view(view_id, view_type, **options) |
| 42 | + if view_type == "form": |
| 43 | + if ( |
| 44 | + self.env.user.has_group("sales_team.group_sale_salesman") |
| 45 | + or self.env.user.has_group("sales_team.group_sale_salesman_all_leads") |
| 46 | + ) and not self.env.user.has_group("sales_team.group_sale_manager"): |
| 47 | + fields = arch.xpath("//form") |
| 48 | + for node in fields: |
| 49 | + node.set("edit", "false") |
| 50 | + return arch, view |
0 commit comments