Skip to Content
Menu
This question has been flagged
6 Replies
2110 Views

Hi all:

I worked with Odoo10CE, in the sales.order.line model, I want to add a new many2one field, to get the value of product barcode from field from product.supplierinfo model. 

When I add new x_product_barcode field in sales.order.line model and use many2one type, there is also settting of Object Relation, I set this to product.supplierinfo. But how to correlated my x_product_barcode field to product_code field of product.supplierinfo model?

I need to write some code on sales.order.line form view xml? Or also need to write some python code in sales.order.line model?

Thank you very much in advance!

Best regards,

John

Avatar
Discard
Author Best Answer

Thank you Waleed, but can I just configure in the interface to achieve this without Python coding?

Avatar
Discard

No you can't because supplierinfo is part of purchase not from sale and to achieve that you have to use python code to add the field and link it to product_code.

Author

Hi Mohsen:

I spend some time to work on this, but I am not familiar with coding. When I need is as following:

I want to add customized field <Item Number> for each product, and this field information needs to be displayed on product page, sales quotation and sales order pages, and also on RFQ and purchase order pages.

I can add a customized field x_PN with type as char on product.template module, and product.product module will copy this x_PN automatically.

I can also add a customized field on sale.order.line module, and related by product.tmpl.id field and show this <item number> no problem. But I cannot do the same with purchase.order and purchase.order.line module.

And I tried to add many2one field on product, and add many2one on purchase.order and purchase.order.line. But cannot get success.

I am looking for a method to do this without coding.

You cannot add field to model without coding. since you already add x_PN to product.product model so you can add related field to purcahse order as below:

from odoo import api, fields, models, _

class PurchaseOrderLine(models.Model):

_inherit = "purchase.order.line"

x_PN = fields.Char(related='product_id.x_PN', string="Item Number")

Hi Mohsen:

 

Thank you very much for your message and support. I am trying to follow your suggestion to add code, but still meet problems.

 

I add fields through user interface as following:

 

Model: product.template

Field name: x_PN

Field type: char

Field label: Item Number

 

Model: product.product

Field name: x_PN

Field type: char

Field label: Item Number

 

After add field in product.template model, the system will copy it to product.product model.

 

Model: purchase.order.line

Field name: x_purchase_PN

Field type: char

Field label: Item Number

 

But when I download the py files from /usr/lib/python2.7/dist-packages/odoo/addons/

, to get the files product_template.py, product.py and purchase.py, I cannot my my fields in those files. What is the problem?

 

If there are no code of these fields in the py file, I cannot add other code to link them. Really confused.

 

Hope to get your kindly help.

 

Thank you very much again and looking forward to hear from you soon!

 

#We are together, Nothing is impossible, Anything is possible#

 

Best regards,

John-Hongwei.Xu

 

 图片包含 文字

描述已自动生成

 

Palmary Technology Ltd.

Phone: +86-10-63290650

Email: john.xu@palmarytech.com

Mobile: +86-13911116695

Web: www.palmarytech.com

 

Room 1-0001, Building B, Wanxing Plaza,

No.78 West Road of South Third Ring,

Fengtai District,

Beijing 100070, P.R. China 

 

P Consider the environment. Please don't print this e-mail unless you really need to.

 

本邮件及其附件含有北京帕莫瑞科技有限公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件!

 

This e-mail and its attachments contain confidential information from Palmary Technology Ltd., which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!

 

 

 

发件人: Waleed Mohsen <mohsen.waleed@gmail.com>
答复: "Odoo S.A. Re: Odoo 10 ce many2one field setup" <catchall@mail.odoo.com>
日期: 2019920 星期五 上午12:51
收件人: "John-Hongwei.Xu" <john.xu@palmarytech.com>
主题: Re: Odoo 10 ce many2one field setup

 

You cannot add field to model without coding. since you already add x_PN to product.product model so you can add related field to purcahse order as below:

from odoo import api, fields, models, _

class PurchaseOrderLine(models.Model):

_inherit = "purchase.order.line"

x_PN = fields.Char(related='product_id.x_PN', string="Item Number")

Sent by Odoo S.A. using Odoo.

Best Answer

As per your question, you mention you want to get product barcode from supplierinfo but in supplierinfo  there is no product barcode and there is product code.

So let's suppose you want to get the product_code from product.supplierinfo to sale.order.line but the supplierinfo can have multiple records for the same product for different vendors so for which vendor (supplier) you want to get the product_code. 

See in product.product, they get the code as below:

define computed field with _compute_product_code function

code = fields.Char('Reference', compute='_compute_product_code')
@api.one
def _compute_product_code(self):
for supplier_info in self.seller_ids:
if supplier_info.name.id == self._context.get('partner_id'):
self.code = supplier_info.product_code or self.default_code
break
else:
self.code = self.default_code



As you can see in _compute_product_code function, there is a condition to get the product_code for specific vendor (partner).

In your code, How can you get the vendor in sale.order.line? Do you have a field in sale.order.line for vendor?

please clarify more so that I can help you.


Avatar
Discard
Related Posts Replies Views Activity
1
Nov 22
14651
3
Aug 22
10763
2
Aug 22
3052
0
Jul 22
835
2
Oct 21
1437