Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie

Hello, so basically I am new to Odoo any kind of help would be awesome, I am using Odoo 16, and so basically I want the field "Expected Arrival" that is in purchase order model and view, i want it to be displayed with the same value in Product.template and precisely in the "purchase" page in the product.template model.

How can I do that ? 
Thanks ! 

I tried something like that : but I think I messed up something

----------------- 
Model Inherit

-----------

class ProductTemplate(models.Model):

_inherit = "product.template"


date_planned = fields.Datetime(

string='Expected Arrival', index=True, copy=False, store=True, readonly=False,)


and in view in used xpath after the vendor field in the table (in purchase page in product.template) 






Awatar
Odrzuć
Najlepsza odpowiedź

Hi,

To display the "Expected Arrival" field from the Purchase Order model in the "Product" page of the Product Template model.
First of all, Inherit the Product Template model and define a related field in the Product Template model that will fetch the "Expected Arrival" value from the related Purchase Order.
Write a compute function to fetch the most recent Purchase Order for the current product and set the value of the expected_arrival field accordingly. as given below


class ProductTemplate(models.Model):
    _inherit = 'product.template'

    expected_arrival = fields.Date(
        string='Expected Arrival',
compute='_compute_expected_arrival',
        store=True,
        readonly=True
    )

def _compute_expected_arrival(self):
        for product in self:
variant_ids = product.product_variant_ids.mapped('id')
purchase_order = self.env['purchase.order'].search([
                ('order_line.product_id', 'in', variant_ids)
            ], order='date_order desc', limit=1)

            if purchase_order:
product.expected_arrival = purchase_order.expected_arrival_date
            else:
                product.expected_arrival = False
               
  Update the XML view also,
               

<record id="view_product_template_inherit" model="ir.ui.view">
<field name="name">product.template.inherit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
    <field name="arch" type="xml">
        <page name="purchase" position="after">
            <group>
                <field name="expected_arrival"/>
            </group>
        </page>
    </field>
</record>


Hope it helps

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
3
cze 17
5139
2
wrz 23
9853
1
lut 22
6870
2
lis 21
8124
1
lip 21
3640