Skip to content

Commit

Permalink
Merge 2d860bc into 3c47d6d
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn committed Sep 29, 2015
2 parents 3c47d6d + 2d860bc commit c9f5725
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 7 deletions.
8 changes: 3 additions & 5 deletions account_invoice_pricelist/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ Pricelist on Invoices
=====================

* Add a stored field pricelist on invoices, related to the partner pricelist;
* Use this pricelist when manually adding invoice lines
* Possibility to group by pricelist on account.invoice view;

.. image:: static/src/description/screenshot_group_by.png


This module doesn't add real feature by it self for end-users, but is useful
to do reporting, in a inherited module.

Installation
============

Expand Down Expand Up @@ -44,7 +41,7 @@ For further information, please visit:
Known issues / Roadmap
======================

* When changing the pricelist, give the possibility to recompute prices;
None currently

Bug Tracker
===========
Expand All @@ -62,6 +59,7 @@ Contributors
------------

* Sylvain LE GAL (https://twitter.com/legalsylvain)
* Holger Brunn <hbrunn@therp.nl>

Maintainer
----------
Expand Down
2 changes: 1 addition & 1 deletion account_invoice_pricelist/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
'version': '8.0.1.0.0',
'summary': 'Add partner pricelist on invoices',
'category': 'Accounting & Finance',
'author': 'GRAP,Odoo Community Association (OCA)',
'author': 'GRAP,Therp BV,Odoo Community Association (OCA)',
'website': 'http://www.grap.coop',
'license': 'AGPL-3',
'depends': [
Expand Down
1 change: 1 addition & 0 deletions account_invoice_pricelist/model/__init__.py
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
9 changes: 8 additions & 1 deletion account_invoice_pricelist/model/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class AccountInvoice(models.Model):
comodel_name='product.pricelist', string='Pricelist',
help="The pricelist of the partner, when the invoice is created"
" or the partner has changed. This is a technical field used"
" for reporting.")
" for reporting.",
readonly=True, states={'draft': [('readonly', False)]})

@api.multi
def onchange_partner_id(
Expand All @@ -56,3 +57,9 @@ def onchange_partner_id(
partner.property_product_pricelist_purchase.id
res['value']['pricelist_id'] = pricelist_id
return res

@api.multi
def button_update_prices_from_pricelist(self):
for this in self:
this.invoice_line.filtered('product_id').update_from_pricelist()
this.button_reset_taxes()
78 changes: 78 additions & 0 deletions account_invoice_pricelist/model/account_invoice_line.py
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'],
})
20 changes: 20 additions & 0 deletions account_invoice_pricelist/tests/__init__.py
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 account_invoice_pricelist/tests/test_account_invoice_pricelist.py
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()
12 changes: 12 additions & 0 deletions account_invoice_pricelist/view/view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,31 @@
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<field name="state" position="before">
<button type="object" name="button_update_prices_from_pricelist" string="Update prices from pricelist" attrs="{'invisible': ['|', ('pricelist_id', '=', False), ('state', 'not in', ['draft'])]}" />
</field>
<field name="user_id" position="after">
<field name="pricelist_id"/>
</field>
<field name="invoice_line" position="attributes">
<attribute name="context">{'partner_id': partner_id, 'price_type': context.get('price_type') or False, 'type': type, 'pricelist_id': pricelist_id}</attribute>
</field>
</field>
</record>

<record id="view_account_invoice_supplier_form" model="ir.ui.view">
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_supplier_form"/>
<field name="arch" type="xml">
<field name="state" position="before">
<button type="object" name="button_update_prices_from_pricelist" string="Update prices from pricelist" attrs="{'invisible': ['|', ('pricelist_id', '=', False), ('state', 'not in', ['draft'])]}" />
</field>
<field name="user_id" position="after">
<field name="pricelist_id"/>
</field>
<field name="invoice_line" position="attributes">
<attribute name="context">{'partner_id': partner_id, 'price_type': context.get('price_type') or False, 'type': type, 'pricelist_id': pricelist_id}</attribute>
</field>
</field>
</record>

Expand Down

0 comments on commit c9f5725

Please sign in to comment.