123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- # -*- coding: utf-8 -*-
- # Copyright 2016 Onestein (<http://www.onestein.eu>)
- # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
- from openerp import models, fields, api
- class AccountInvoice(models.Model):
- _inherit = 'account.invoice'
- pricelist_id = fields.Many2one(
- 'product.pricelist',
- 'Pricelist',
- help="Pricelist for current invoice.")
- @api.multi
- def onchange_partner_id(self, type, partner_id, date_invoice=False,
- payment_term=False, partner_bank_id=False,
- company_id=False):
- res = super(AccountInvoice, self).onchange_partner_id(
- type, partner_id, date_invoice=False,
- payment_term=False, partner_bank_id=False,
- company_id=False)
- if type in ['out_invoice', 'out_refund']:
- res['value'].update({
- 'pricelist_id': None,
- })
- if partner_id:
- partner = self.env['res.partner'].browse(partner_id)
- if partner.property_product_pricelist:
- res['value'].update({
- 'pricelist_id': partner.property_product_pricelist.id,
- 'currency_id': partner.property_product_pricelist.currency_id.id
- })
- if type in ['in_invoice', 'in_refund']:
- res['value'].update({
- 'pricelist_id': None,
- })
- if partner_id:
- partner = self.env['res.partner'].browse(partner_id)
- if partner.property_product_pricelist_purchase:
- res['value'].update({
- 'pricelist_id': partner.property_product_pricelist_purchase.id,
- 'currency_id': partner.property_product_pricelist.currency_id.id
- })
- return res
- @api.one
- @api.onchange('pricelist_id')
- def onchange_pricelist_id(self):
- self.currency_id = self.pricelist_id.currency_id.id
|