-
-
Notifications
You must be signed in to change notification settings - Fork 665
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
157 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# -*- encoding: utf-8 -*- | ||
|
||
from . import account_invoice | ||
from . import account_invoice_line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# This module copyright (C) 2015 Therp BV (<http://therp.nl>). | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
from openerp import models, api | ||
|
||
|
||
class AccountInvoiceLine(models.Model): | ||
_inherit = 'account.invoice.line' | ||
|
||
@api.multi | ||
def product_id_change( | ||
self, product, uom_id, qty=0, name='', type='out_invoice', | ||
partner_id=False, fposition_id=False, price_unit=False, | ||
currency_id=False, company_id=None): | ||
result = super(AccountInvoiceLine, self).product_id_change( | ||
product, uom_id, qty=qty, name=name, type=type, | ||
partner_id=partner_id, fposition_id=fposition_id, | ||
price_unit=price_unit, currency_id=currency_id, | ||
company_id=company_id) | ||
values = result.get('value', {}) | ||
if product and 'pricelist_id' in self.env.context: | ||
# get pricelist price | ||
values['price_unit'] = self.env['product.product']\ | ||
.browse([product])\ | ||
.with_context( | ||
quantity=qty, pricelist=self.env.context['pricelist_id'], | ||
partner=partner_id)\ | ||
._product_price(None, None)\ | ||
.get(product) | ||
# adjust for currency, uos (taken from super) | ||
if company_id and currency_id: | ||
company = self.env['res.company'].browse([company_id]) | ||
product = self.env['product.product'].browse([product]) | ||
currency = self.env['res.currency'].browse([currency_id]) | ||
if company.currency_id != currency: | ||
if type in ('in_invoice', 'in_refund'): | ||
values['price_unit'] = product.standard_price | ||
values['price_unit'] = values['price_unit'] * currency.rate | ||
|
||
if values['uos_id'] and values['uos_id'] != product.uom_id.id: | ||
values['price_unit'] = self.env['product.uom']\ | ||
._compute_price(product.uom_id.id, | ||
values['price_unit'], values['uos_id']) | ||
return result | ||
|
||
@api.multi | ||
def update_from_pricelist(self): | ||
"""overwrite current prices from pricelist""" | ||
for this in self: | ||
values = this\ | ||
.with_context(pricelist_id=this.invoice_id.pricelist_id.id)\ | ||
.product_id_change( | ||
this.product_id.id, this.uos_id.id, qty=this.quantity, | ||
name=this.name, type=this.invoice_id.type, | ||
partner_id=this.invoice_id.partner_id.id, | ||
fposition_id=this.invoice_id.fiscal_position.id, | ||
price_unit=this.price_unit, | ||
currency_id=this.invoice_id.currency_id.id, | ||
company_id=this.invoice_id.company_id.id)['value'] | ||
this.write({ | ||
'price_unit': values['price_unit'], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# This module copyright (C) 2015 Therp BV <http://therp.nl>. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
from . import test_account_invoice_pricelist |
34 changes: 34 additions & 0 deletions
34
account_invoice_pricelist/tests/test_account_invoice_pricelist.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# This module copyright (C) 2015 Therp BV <http://therp.nl>. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
from openerp.tests.common import TransactionCase | ||
|
||
|
||
class TestAccountInvoicePricelist(TransactionCase): | ||
def test_account_invoice_pricelist(self): | ||
invoice = self.env['account.invoice'].search([ | ||
('type', '=', 'out_invoice'), | ||
('partner_id.property_product_pricelist', '!=', False) | ||
], limit=1) | ||
on_change_partner_id = invoice.onchange_partner_id( | ||
invoice.type, invoice.partner_id.id) | ||
self.assertEqual( | ||
on_change_partner_id['value']['pricelist_id'], | ||
invoice.partner_id.property_product_pricelist.id) | ||
invoice.button_update_prices_from_pricelist() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters