top of page

Odoo Quotation - Restrict Delivery Invoice Address and Delivery Address

  • Writer: Tek Siong, Hock
    Tek Siong, Hock
  • Sep 21, 2021
  • 1 min read

In the standard Odoo, after user has selected the Customer, user is still allowed to select any Invoice and Delivery address from other customer. This may offer flexibilities, but often very susceptible to the human error.


In the sales.order model, add the following domain in the quotation to restrict to the customer's own invoice or delivery address.

@api.multi
@api.onchange('partner_id')
def onchange_partner_id(self):
    super(SaleQuotation, self).onchange_partner_id()
    partners_invoice = []
    partners_shipping = []
    domain = {}
    for record in self:
        if record.partner_id:
            record.partner_invoice_id = record.partner_id.id
            record.partner_shipping_id = record.partner_id.id
            if record.partner_id.child_ids:
                for partner in record.partner_id.child_ids:
                    if partner.type == 'invoice':
                        partners_invoice.append(partner.id)
                    if partner.type == 'delivery':
                        partners_shipping.append(partner.id)
            if partners_invoice:
                domain['partner_invoice_id'] = [('id', 'in', partners_invoice)]
            else:
                partners_invoice.append(record.partner_id.id)
                domain['partner_invoice_id'] = [('id', 'in', partners_invoice)]
            if partners_shipping:
                domain['partner_shipping_id'] = [('id', 'in', partners_shipping)]
            else:
                partners_shipping.append(record.partner_id.id)
                domain['partner_shipping_id'] = [('id', 'in', partners_shipping)]

        else:
            domain['partner_invoice_id'] = [('type', '=', 'invoice')]
            domain['partner_shipping_id'] = [('type', '=', 'delivery')]

    return {'domain': domain}

Recent Posts

See All
Odoo Performance Profile for debugging

Odoo Performance Profile for debugging, If you are on Odoo 16 and below, and need a good tool for debugging the performance of your Odoo system, this will be the right content for you.

 
 
 

Comentários


Subscribe Form

  • facebook
  • linkedin

©2019 by Excelroot Technology Sdn Bhd.

bottom of page