top of page
Writer's pictureTek Siong, Hock

Odoo Quotation - Restrict Delivery Invoice Address and Delivery Address

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}

94 views0 comments

Recent Posts

See All

Comments


bottom of page