Skip to Content
Menu
This question has been flagged
2 Replies
8533 Views

I have a very strange problem concerning sale.order.line and sale.order. To the background: In the product.template there is a relation to a "Product Description" where I can store several Values (One2many).

When I choose a product in the the sale.order.line, the available descriptions are loaded also in a new relation to the sale.order.line. This is needed to change the description temporary.

I insert the available description lines with an onchange method which works fine. But the problem is when I am trying to insert a new record. When I click on "save" at the sale.order.line Odoo jumps back to the sale.order. When I am now saving the sale.order the one2many-entry values (description in the sale.order.line) disappear. The relation exist, but the fields of the description in the sale.order.line are empty. Can anybody help me. Thank you! Here are the code snippets:

Own model for the description:

#Product Description Name
class product_description_name(models.Model):
     _name = 'x_article.product_description_name'
     name = fields.Char(string="Bezeichnung", required=True)
     product_description_ids = fields.One2many('x_article.product_description', 'pdm_id', string="Artikel")
 
class product_description(models.Model):
     _name = 'x_article.product_description'
     _order = 'sequence'
 
     sequence = fields.Integer(string='Sequence', default=1)
     pdm_id = fields.Many2one('x_article.product_description_name', string="Bezeichnung")
     text = fields.Char(string="Eigenschaft")
     article_id = fields.Many2one('product.template', string="Artikel")
     sale_order_line_id = fields.Many2one('sale.order.line', string="Bestellposition")
 
     on_doc = fields.Boolean(string="sämtliche Dokumente", default=False)
     on_offer = fields.Boolean(string="Angebot/Webshop", default=False)
 
 
<xpath expr="//field[@name='order_line']/form//field[@name='name']" position="after">
     <field name="name_offer" attrs="{'invisible': [('state','!=', 'draft')]}" />
     <field name="id" invisible="1" />
     <field name="article_description_ids" nolabel="1" context="{'default_sale_order_line_id': active_id}">
          <tree editable="true">
               <field name="sequence" widget="handle" />
               <field name="pdm_id" options="{'no_create': True}" />
               <field name="text" /> <field name="on_doc" />
               <field name="on_offer" />
               <field name="article_id" invisible="1" />
               <field name="sale_order_line_id" />
          </tree>
     </field>
</xpath>
Avatar
Discard
Author Best Answer

Thank you for your response!


Here is my @onchange method. Thank you for your help


@api.onchange('product_id')
def _change_product_description_text(self):
    val = []
    if not self.product_id:
        self.article_description_ids = False
        return
    else:
        self.article_description_ids = False
        for i in self.product_id.product_tmpl_id.product_description_id:
            self.article_description_ids += self.article_description_ids.create({
                                                                                                                                'sequence': 1,
                                                                                                                                'pdm_id': i.pdm_id.id,
                                                                                                                                'text': i.text,
                                                                                                                                'sale_order_line_id': self.id,
                                                                                                                                'on_doc': i.on_doc,
                                                                                                                                'on_offer': i.on_offer })
        if len(self.article_description_ids) == 0:
            self.name = self.product_id.name_get()[0][1]
            self.name_offer = self.product_id.name_get()[0][1]
    self._get_additional_products()

Avatar
Discard
Best Answer

Hi,
I'm facing a similar problem and want to report it as a bug to odoo. But for this, I need to have it reproducable. Can you maybe also post your onchange method or even better share the whole custom addon?

Best regards,

Olivier Jossen

Avatar
Discard