add new tap in product.tem ####
mg5714 opened this issue · comments
product_test.py
(The code works and there are no errors.
But when I select the product and Alternative products in the product.template
When I go to the purchase order and choose the product and enter the new tab (Alternative), other products appear to me other than the ones I previously chose)
so, any one help me !!
#######################
from odoo import models, fields, api
class product_test(models.Model):
_inherit = 'product.template'
name = fields.Char(string="Name")
alter_ids = fields.Many2many("product.product", "product_tmpl", string="Alternative Products")
class purchase_test(models.Model):
_inherit = 'purchase.order'
prodct_alternaitve_ids = fields.Many2many("product.template", "product_id",string="Product Alternaitve")
@api.onchange('order_line')
def onchange_alter_ids(self):
test_list =[]
for rec in self:
if rec.order_line.product_id:
print(rec.product_id,"################")
alternative_products = rec.order_line.product_id.alter_ids
for i in alternative_products:
print(i.id,"@@@")
test_list.append(i.id)
print(test_list)
rec.write({'prodct_alternaitve_ids': [(4, i.id)]})
xml File
#############
product.template.form product.template <!-- ###########################################PO############################# -->
<record id="purchase_order_form_test" model="ir.ui.view">
<field name="name">purchase.order.form</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<xpath expr="//page[@name='purchase_delivery_invoice']" position='after'>
<page string="Alternaitve">
<field name='prodct_alternaitve_ids'/>
</page>
</xpath>
</field>
</record>
</data>