需要一个示例工作代码,以便我可以尝试更好地了解它在Odoo 12中的销售点应用程序中如何工作。
我试图将新的自定义字段添加到“ pos.order.line”以用于销售点应用程序,而我对Odoo 12 pos不满意。
这个新领域取决于我创建的用于产品的新模型。
我将此字段添加到模型中,我需要在每个产品的每个pos订单行上自动填写该字段。
就像“税”一样,当用户选择一种产品时,Odoo会在“订单行”上自动设置税信息。
为了更好地理解,我将尝试重现到目前为止已完成的步骤。
1.新模型:在本示例中,我将其称为“类型”。
该模型将填充“几种”类型,并添加到我拥有的每个产品中。
class Types(models.Model):
_name = 'types'
_description = 'Sample Types Model'
code = fields.Char('Code', required=True)
name = fields.Char('Description', required=True)
2.此“类型”信息将添加到我拥有的每个产品中,因此,我在“ products.template”模型中添加了一个新字段:
class ProductTemplate(models.Model):
_inherit = "product.template"
types_id = fields.Many2one('types', string='Product specific type')
3.由于我需要将此值显示在每个pos订单行上,因此我使用相同的方法将字段添加到“ pos.order.line”模型中:
class PosOrderLine(models.Model):
_inherit = "pos.order.line"
types_id = fields.Many2one('types', string='Product specific type')
4.从这里开始问题。
当产品添加到购物篮时,我需要加载新模型并将新字段添加到“ product.template”,并在“ pos.order.line”上为每个产品写入默认的“类型”。
在PoS上,我需要:
加载新模型和字段;
将订单添加到购物篮时,将值写入pos.order.line;
谁能帮我吗?
最佳答案
您可以将types_id
related设置为product_id.product_tmpl_id.types_id
,它将自动填充。
class PosOrderLine(models.Model):
_inherit = "pos.order.line"
types_id = fields.Many2one(related='product_id.product_tmpl_id.types_id',
string='Product specific type')
关于javascript - 加载自定义模型并在销售点-Odoo 12中向pos.order.line添加一个字段,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60913981/