Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
1 Vastaa
1580 Näkymät

Hello, I am wondering if it is possible to add a text field within the product variant section.  For example, I sell House Numbers which are customized with the buyers house or street number engraved on it.  How can I add a field so they can enter the number?  Odoo 16 user.

Avatar
Hylkää
Paras vastaus

Hi,

In your module, create a Python file (e.g., models/models.py) and define a new model to store the custom field.


from odoo import models, fields


class ProductTemplate(models.Model):

    _inherit = 'product.template'


    engraved_number = fields.Char(string='Engraved Number')



In the same Python file, extend the product variant form view to include the custom field.

from odoo import api, fields, models

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

    engraved_number = fields.Char(string='Engraved Number')

class ProductProduct(models.Model):
    _inherit = 'product.product'

engraved_number = fields.Char(string='Engraved Number', related='product_tmpl_id.engraved_number')


Create an XML file (e.g., views/product_variant_view.xml) to modify the product variant form view.

<odoo>
<record id="product_variant_form_inherit" model="ir.ui.view">
<field name="name">product.product_template_only_form_view</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
        <field name="arch" type="xml">
            <group>
                <field name="engraved_number"/>
            </group>
        </field>
    </record>
</odoo>


Hope it helps

Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
1
heinäk. 25
608
1
maalisk. 15
4323
3
toukok. 25
1658
3
marrask. 24
8445
2
elok. 24
1813