Skip to content

Commit

Permalink
Merge 11c23eb into feffb06
Browse files Browse the repository at this point in the history
  • Loading branch information
tafaRU committed Sep 15, 2015
2 parents feffb06 + 11c23eb commit c3f3d89
Show file tree
Hide file tree
Showing 8 changed files with 328 additions and 0 deletions.
48 changes: 48 additions & 0 deletions account_invoice_uom/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3

Unit of measure for invoices
============================

The module displays the internal UoM and quantity on the invoice lines,
retrieving them from the linked sale order(s), or from the picking lines
(when the invoice is based on delivery).

Usage
=====

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/95/8.0

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-invoicing/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
`here <https://github.com/OCA/account-invoicing/issues/new?body=module:%20account_invoice_uom%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Credits
=======

Contributors
------------

* Lorenzo Battistini <lorenzo.battistini@agilebg.com>
* Alex Comba <alex.comba@agilebg.com>

Maintainer
----------

.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit http://odoo-community.org.
22 changes: 22 additions & 0 deletions account_invoice_uom/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2014-15 Agile Business Group sagl (<http://www.agilebg.com>)
# Author: Lorenzo Battistini <lorenzo.battistini@agilebg.com>
#
# 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 account_invoice_line
40 changes: 40 additions & 0 deletions account_invoice_uom/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2014-15 Agile Business Group sagl (<http://www.agilebg.com>)
# Author: Lorenzo Battistini <lorenzo.battistini@agilebg.com>
#
# 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/>.
#
##############################################################################
{
"name": "Unit of measure for invoices",
"version": "8.0.1.0.0",
'author': "Agile Business Group, Odoo Community Association (OCA)",
"website": "http://www.agilebg.com",
'license': 'AGPL-3',
"category": "Account",
"depends": [
'sale_stock',
'stock_picking_invoice_link',
],
"demo": [],
"data": [
'account_invoice_line_view.xml',
],
'test': [
'test/account_invoice_uom.yml',
],
'installable': True,
}
65 changes: 65 additions & 0 deletions account_invoice_uom/account_invoice_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2014-15 Agile Business Group sagl (<http://www.agilebg.com>)
# Author: Lorenzo Battistini <lorenzo.battistini@agilebg.com>
#
# 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.osv import orm, fields
import openerp.addons.decimal_precision as dp


class AccountInvoiceLine(orm.Model):

def _get_uom_data(self, cr, uid, ids, field_name, arg, context):
res = {}
sale_line_obj = self.pool['sale.order.line']
for line in self.browse(cr, uid, ids, context=context):
res[line.id] = {
'uom_id': False,
'uom_qty': False,
}
if line.move_line_ids and len(line.move_line_ids) == 1:
res[line.id]['uom_id'] = (
line.move_line_ids[0].product_uom.id
if line.move_line_ids[0].product_uom else False
)
res[line.id]['uom_qty'] = line.move_line_ids[0].product_qty
else:
so_line_ids = sale_line_obj.search(
cr, uid, [('invoice_lines', 'in', [line.id])],
context=context
)
if len(so_line_ids) == 1:
so_line = sale_line_obj.browse(
cr, uid, so_line_ids[0], context=context)
res[line.id]['uom_id'] = (
so_line.product_uom.id
if so_line.product_uom else False
)
res[line.id]['uom_qty'] = so_line.product_uom_qty
return res

_inherit = "account.invoice.line"
_columns = {
'uom_id': fields.function(
_get_uom_data, string="Internal UoM", type="many2one",
relation='product.uom', multi="uom"),
'uom_qty': fields.function(
_get_uom_data, string="Internal quantity", type="float",
digits_compute=dp.get_precision('Product UoS'), multi="uom")
}
30 changes: 30 additions & 0 deletions account_invoice_uom/account_invoice_line_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_invoice_line_form_uos" model="ir.ui.view">
<field name="name">view_invoice_line_form_uos</field>
<field name="model">account.invoice.line</field>
<field name="inherit_id" ref="account.view_invoice_line_form"></field>
<field name="arch" type="xml">
<xpath expr="//form/group/group/div" position="after">
<label for="uom_qty" groups="product.group_uom"/>
<div groups="product.group_uom">
<field name="uom_qty" class="oe_inline"/>
<field name="uom_id" class="oe_inline"/>
</div>
</xpath>
</field>
</record>
<record id="invoice_form_uos" model="ir.ui.view">
<field name="name">invoice_form_uos</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"></field>
<field name="arch" type="xml">
<field name="uos_id" position="after">
<field name="uom_qty" groups="product.group_uom"/>
<field name="uom_id" groups="product.group_uom"/>
</field>
</field>
</record>
</data>
</openerp>
32 changes: 32 additions & 0 deletions account_invoice_uom/i18n/account_invoice_uom.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_invoice_uom
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-09-15 09:24+0000\n"
"PO-Revision-Date: 2015-09-15 09:24+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: account_invoice_uom
#: field:account.invoice.line,uom_id:0
msgid "Internal UoM"
msgstr ""

#. module: account_invoice_uom
#: field:account.invoice.line,uom_qty:0
msgid "Internal quantity"
msgstr ""

#. module: account_invoice_uom
#: model:ir.model,name:account_invoice_uom.model_account_invoice_line
msgid "Invoice Line"
msgstr ""

Binary file added account_invoice_uom/static/description/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 91 additions & 0 deletions account_invoice_uom/test/account_invoice_uom.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
-
In order to test process of the Account Invoice Uom,
-
I create a sale order.
-
!record {model: sale.order, id: sale_order_test}:
partner_id: base.res_partner_2
order_line:
- product_id: product.product_product_3
product_uom_qty: 1
product_uom: product.product_uom_unit
product_uos_qty: 2
product_uos: product.product_uom_kgm
-
I confirm the sale order.
-
!workflow {model: sale.order, action: order_confirm, ref: sale_order_test}
-
I create advance invoice where type is 'Invoice all the Sale Order'.
-
!python {model: sale.advance.payment.inv}: |
ctx = context.copy()
ctx.update({"active_model": 'sale.order', "active_ids": [ref("sale_order_test")], "active_id":ref("sale_order_test")})
pay_id = self.create(cr, uid, {'advance_payment_method': 'all'})
self.create_invoices(cr, uid, [pay_id], context=ctx)
-
I check invoice which made advance where type is 'Invoice all the Sale Order'.
-
!python {model: sale.order}: |
order = self.browse(cr, uid, ref('sale_order_test'))
assert order.invoice_ids, "Invoice should be created after make advance invoice where type is 'Invoice all the Sale Order'."
-
I check the UoS and related quantity on invoice lines.
-
!python {model: sale.order}: |
order = self.browse(cr, uid, ref("sale_order_test"))
for sale_line in order.order_line:
assert sale_line.invoice_lines, "Invoice lines on the sale order line should be created"
for invoice_line in sale_line.invoice_lines:
assert invoice_line.uom_id.id == ref('product.product_uom_unit'), "Uom are not matching"
assert invoice_line.uom_qty == 1, "Uom qty are not matching"
assert invoice_line.uos_id.id == ref('product.product_uom_kgm'), "UoS are not matching"
assert invoice_line.quantity == 2, "UoS qty are not matching"
-
I create another sale order, with invoice based on picking
-
!record {model: sale.order, id: sale_order_test_2}:
partner_id: base.res_partner_2
order_policy: 'picking'
order_line:
- product_id: product.product_product_3
product_uom_qty: 1
product_uom: product.product_uom_unit
product_uos_qty: 2
product_uos: product.product_uom_kgm
-
I confirm the sale order.
-
!workflow {model: sale.order, action: order_confirm, ref: sale_order_test_2}
-
Now, I dispatch delivery order.
-
!python {model: stock.transfer_details}: |
order = self.pool.get('sale.order').browse(cr, uid, ref("sale_order_test_2"))
for pick in order.picking_ids:
data = pick.force_assign()
if data == True:
partial_id = self.create(cr, uid, {}, context={'active_model': 'stock.picking','active_ids': [pick.id]})
self.do_detailed_transfer(cr, uid, [partial_id])
-
I create Invoice from Delivery Order.
-
!python {model: stock.invoice.onshipping}: |
sale = self.pool.get('sale.order')
sale_order = sale.browse(cr, uid, ref("sale_order_test_2"))
ship_ids = [x.id for x in sale_order.picking_ids]
wiz_id = self.create(cr, uid, {'journal_id': ref('account.sales_journal')},
{'active_ids': ship_ids, 'active_model': 'stock.picking'})
self.create_invoice(cr, uid, [wiz_id], {"active_ids": ship_ids, "active_id": ship_ids[0]})
-
I check the invoice details after dispatched delivery.
-
!python {model: sale.order}: |
order = self.browse(cr, uid, ref("sale_order_test_2"))
assert order.invoice_ids, "Invoice is not created."
assert len(order.invoice_ids) == 1, "There must be 1 invoice"
assert len(order.invoice_ids[0].invoice_line) == 1, "There must be 1 invoice line"
assert order.invoice_ids[0].invoice_line[0].uom_id.id == ref('product.product_uom_unit'), "Uom are not matching"
assert order.invoice_ids[0].invoice_line[0].uom_qty == 1, "Uom qty are not matching"
assert order.invoice_ids[0].invoice_line[0].uos_id.id == ref('product.product_uom_kgm'), "UoS are not matching"
assert order.invoice_ids[0].invoice_line[0].quantity == 2, "UoS qty are not matching"

0 comments on commit c3f3d89

Please sign in to comment.