Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
4476 Lượt xem

hi.

i help me with please:

i want show the client when generating a production order, this is possible?

client = fields.Many2one('sale.order', string='Client',domain=[('sale_ok', '=', True)], change_default=True, ondelete='restrict')​

this code shows the code or folio but i want the client

i think it´s just in domain

thank you 




Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

First of all, there should be a link established between the models sale.order and mrp.production.


To store the value of the sale order in the mrp.production, inherit and add a many2one field of the sale order in it.


class MrpProduction(models.Model):
_inherit = 'mrp.production'

    sale_order_id = fields.Many2one('sale.order', string='Sale Order')

    partner_id = fields.Many2one('res.partner', related='sale_order_id.partner_id', string="Cusromer")

Also in the above code, we have added a related field of the model res.partner to store the value of the customer in the sale order inside the mrp.production. As it related field it will take the value from the sale.order model.


Then you can inherit the procurement.order model and super the function _prepare_mo_vals to pass the sale order id to the new field added in the mrp.production.


@api.model
def _prepare_mo_vals(self, bom):
    vals = super(ProcurementOrder, self)._prepare_mo_vals(bom)
    if self.group_id:
        sales = self.env['sale.order'].search([('procurement_group_id', '=', self.group_id.id)])
        if len(sales) > 1:
            raise exceptions.ValidationError(_('More than 1 sale order found for this group'))
        vals['sale_order_id'] = sales.id
    return vals


Now you can inherit the corresponding views and add the newly added fields in the views so that it can be seen in the UI.


For adding the new fields to the existing view, you can check this blog: Add Custom Fields to Existing Views


The code for establishing the connection between sale order and mrp production is taken from this OCA Module: Sale MRP Link


Thanks

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

good day

 i have a ploblem the model procurement.order no exists in odoo 12, i but thanks you


Ảnh đại diện
Huỷ bỏ

yes, the answer was based on the v10, from v11 onwards the same model was removed in odoo, will check and update the answer

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 6 19
7130
1
thg 3 15
4124
0
thg 3 15
3183
1
thg 3 15
5437
5
thg 12 22
19237