Hola, estoy intentando crear una relación One2many en la que no llamo al campo One2many directamente, sino que quiero que se relacione sólo y directamente introducir los valores en los campos relacionados.
¿cómo puedo hacer para que se asignen directamente la relación? Gracias.
He visto que tal y como está, si creo por medio de un campo one2many y asigno el producto manualmente, se crea la bd y puedo incluso cambiar los valores relacionados correctamente. Pero no sé como hacer que cuando se elija área, se cree automáticamente esa relación.
python
class ProductTemplate(models.Model):
_inherit = 'product.template'
sale_price_type = fields.Selection([
('area', 'Area')],
string='Sale Price Type',
required=True,
default='standard',
)
sale_prices_area = fields.One2many('product.prices_area',
'sale_area_tmpl_id',
string="Sale Prices Area")
"""
No quiero que se creen los campos en la tabla product_template
por esto de este campo relativo
"""
min_width = fields.Float(related='sale_prices_area.min_width')
class ProductPricesArea(models.Model):
_name = 'product.prices_area'
min_width = fields.Float(string="Min. Width", default=0.0,
digits=dp.get_precision('Product Price'))
sale_area_tmpl_id = fields.Many2one('product.template', 'Product Template')
xml
<?xml version="1.0"?>
<odoo>
<record id="view_product_template_form_price_type" model="ir.ui.view">
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='list_price']" position="before">
<label for="sale_price_type"/>
<div>
<field name="sale_price_type"/>
</div>
</xpath>
</field>
</record>
<record id="view_product_template_form" model="ir.ui.view">
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<xpath expr="//notebook/page[1]" position="after">
<page string="Sale Price Type">
<group>
<field name="min_width"/>
</group>
</page>
</xpath>
</field>
</record>
</odoo>