콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1949 화면

If a customer has a few of the same products we offer but with a different part number can the respective customer part number be included on the sale order acknowledgement report. I'm not sure if a onetomany field should be added to the product template or the customer and how the report can be modified to know to include the customer's part number if the respective product is a sale order line. I'm fairly new working with Odoo 16 and not too savvy in Python, but use studio customizations. 

아바타
취소

you can add a One2many field in the customer model to associate each product with its corresponding part number for that customer. Here's an example of how you can achieve this:

  1. Add a One2many field in the customer model: In your custom module, add a One2many field to the customer model (res.partner) to store the customer's part numbers for each product. For example:

from odoo import fields, models

class ResPartner(models.Model):
_inherit = 'res.partner'

customer_part_numbers = fields.One2many(
comodel_name='customer.part.number',
inverse_name='customer_id',
string='Customer Part Numbers',
)

  1. Create a new model for customer part numbers: Create a new model in your custom module, let's call it customer.part.number, to store the customer's part number for each product. This model will have a Many2one field to associate it with the product and the customer. For example:

from odoo import fields, models

class CustomerPartNumber(models.Model):
_name = 'customer.part.number'
_description = 'Customer Part Number'

customer_id = fields.Many2one(
comodel_name='res.partner',
string='Customer',
required=True,
)
product_id = fields.Many2one(
comodel_name='product.template',
string='Product',
required=True,
)
part_number = fields.Char(string='Part Number')

  1. Customize the sale order acknowledgement report: Using Odoo Studio, you can customize the sale order acknowledgement report template to include the customer's part number for each product. In the report template, you can iterate over the sale order lines and retrieve the customer's part number based on the customer and product. Here's an example snippet to give you an idea:


tbody>
t t-foreach="o.order_line" t-as="line">
tr>
td>
td>
td>
!-- Add the customer part number column -->
td>
span t-esc="get_customer_part_number(o.partner_id.id, line.product_id.id)"/>
td>
/tr>
/t>
/tbody>

In the above snippet, the get_customer_part_number function is used to retrieve the customer's part number for the given customer and product. You'll need to define this function in the report's Python code to fetch the corresponding part number from the customer.part.number model.



작성자

Thank you! this worked and I'm all set.