Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
2
product_customerinfo_elaboration/models/__init__.py
Executable file
2
product_customerinfo_elaboration/models/__init__.py
Executable file
@@ -0,0 +1,2 @@
|
||||
from . import product_customerinfo
|
||||
from . import sale_order_line
|
||||
19
product_customerinfo_elaboration/models/product_customerinfo.py
Executable file
19
product_customerinfo_elaboration/models/product_customerinfo.py
Executable file
@@ -0,0 +1,19 @@
|
||||
# Copyright 2022 Tecnativa - Carlos Roca
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class ProductCustomerInfo(models.Model):
|
||||
_inherit = "product.customerinfo"
|
||||
|
||||
elaboration_ids = fields.Many2many(comodel_name="product.elaboration")
|
||||
elaboration_note = fields.Char(
|
||||
store=True,
|
||||
compute="_compute_elaboration_note",
|
||||
readonly=False,
|
||||
)
|
||||
|
||||
@api.depends("elaboration_ids")
|
||||
def _compute_elaboration_note(self):
|
||||
for line in self:
|
||||
line.elaboration_note = ", ".join(line.elaboration_ids.mapped("name"))
|
||||
50
product_customerinfo_elaboration/models/sale_order_line.py
Executable file
50
product_customerinfo_elaboration/models/sale_order_line.py
Executable file
@@ -0,0 +1,50 @@
|
||||
# Copyright 2022 Tecnativa - Carlos Roca
|
||||
# Copyright 2023 Tecnativa - Sergio Teruel
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class SaleOrderLine(models.Model):
|
||||
_inherit = "sale.order.line"
|
||||
|
||||
elaboration_ids = fields.Many2many(
|
||||
comodel_name="product.elaboration",
|
||||
compute="_compute_elaboration_ids",
|
||||
store=True,
|
||||
readonly=False,
|
||||
string="Elaborations",
|
||||
)
|
||||
|
||||
@api.depends("product_id")
|
||||
def _compute_elaboration_ids(self):
|
||||
for line in self:
|
||||
customer_info = line._get_product_customer_info()
|
||||
if customer_info:
|
||||
line.elaboration_ids = customer_info.elaboration_ids
|
||||
|
||||
def _get_product_customer_info(self):
|
||||
customerinfo = self.product_id.customer_ids.filtered(
|
||||
lambda pc: pc.elaboration_ids and pc.partner_id == self.order_id.partner_id
|
||||
)[:1]
|
||||
if not customerinfo:
|
||||
customerinfo = self.product_id.customer_ids.filtered(
|
||||
lambda pc: pc.elaboration_ids
|
||||
and pc.partner_id == self.order_id.partner_id.commercial_partner_id
|
||||
)[:1]
|
||||
return customerinfo
|
||||
|
||||
@api.onchange("elaboration_ids")
|
||||
def onchange_elaboration_ids(self):
|
||||
for line in self:
|
||||
customer_info = line._get_product_customer_info()
|
||||
if (
|
||||
customer_info
|
||||
and line.elaboration_ids
|
||||
and (
|
||||
# Comparing with ids because comparison with newId doesn't work
|
||||
line.elaboration_ids.ids == customer_info.elaboration_ids.ids
|
||||
or not line.elaboration_ids
|
||||
)
|
||||
):
|
||||
line.elaboration_note = customer_info.elaboration_note
|
||||
Reference in New Issue
Block a user