Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] modules 'purchase_return' and 'purchase_invoice_status'
- Loading branch information
1 parent
fe899f9
commit 23f0cdf
Showing
17 changed files
with
686 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
|
||
======================= | ||
Purchase Invoice Status | ||
======================= | ||
|
||
This module extends the functionality of purchase orders in order to handle | ||
the invoice status in purchase orders equivalently of how it is done in sales | ||
orders. | ||
|
||
Usage | ||
===== | ||
Pending | ||
|
||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
:alt: Try me on Runbot | ||
:target: https://runbot.odoo-community.org/runbot/142/9.0 | ||
|
||
Known issues / Roadmap | ||
====================== | ||
|
||
* Pending | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues | ||
<https://github.com/OCA/purchase-workflow/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. | ||
|
||
Credits | ||
======= | ||
|
||
Images | ||
------ | ||
|
||
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. | ||
|
||
Contributors | ||
------------ | ||
|
||
* Jordi Ballester Alomar <jordi.ballester@eficent.com> | ||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://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 https://odoo-community.org. |
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,6 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Eficent Business and IT Consulting Services, S.L. | ||
# <contact@eficent.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import models |
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,21 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Eficent Business and IT Consulting Services, S.L. | ||
# <contact@eficent.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Purchase Invoice Status", | ||
"summary": "Compute the invoice status for purchase orders", | ||
"version": "9.0.1.0.0", | ||
"category": "Purchases", | ||
"website": "https://github.com/OCA/account-invoicing", | ||
"author": "Eficent, Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"application": False, | ||
"installable": True, | ||
"depends": [ | ||
"purchase", | ||
], | ||
"data": [ | ||
"views/purchase_view.xml", | ||
], | ||
} |
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,7 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Eficent Business and IT Consulting Services, S.L. | ||
# <contact@eficent.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import purchase_order | ||
from . import account_invoice |
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,33 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com> | ||
# Copyright 2017 Eficent Business and IT Consulting Services | ||
# <contact@eficent.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from openerp import api, models, fields | ||
|
||
|
||
class AccountInvoice(models.Model): | ||
_inherit = "account.invoice" | ||
|
||
@api.onchange('state', 'partner_id', 'invoice_line_ids') | ||
def _onchange_allowed_purchase_ids(self): | ||
''' | ||
The purpose of the method is to define a domain for the available | ||
purchase orders. | ||
''' | ||
result = super(AccountInvoice, self)._onchange_allowed_purchase_ids() | ||
result['domain']['purchase_id'] += [ | ||
('state', 'not in', ['done', 'cancel'])] | ||
return result | ||
|
||
@api.onchange('purchase_id') | ||
def purchase_order_change(self): | ||
if not self.purchase_id: | ||
return {} | ||
if not self.partner_id: | ||
self.partner_id = self.purchase_id.partner_id.id | ||
if self.purchase_id.state in ['done', 'cancel']: | ||
self.purchase_id = False | ||
return {} | ||
super(AccountInvoice, self).purchase_order_change() |
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,153 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Eficent Business and IT Consulting Services, S.L. | ||
# <contact@eficent.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from openerp import api, models, fields | ||
from openerp.tools import float_is_zero, float_compare | ||
|
||
|
||
class PurchaseOrder(models.Model): | ||
_inherit = "purchase.order" | ||
|
||
@api.depends('order_line.qty_received') | ||
def _get_invoiced(self): | ||
precision = self.env['decimal.precision'].precision_get( | ||
'Product Unit of Measure') | ||
super(PurchaseOrder, self)._get_invoiced() | ||
for order in self: | ||
for line in order.order_line: | ||
if line.state == 'purchase' and \ | ||
line.product_id.purchase_method == 'receive': | ||
if not float_is_zero(line.qty_to_invoice, | ||
precision_digits=precision): | ||
break | ||
elif float_compare(line.qty_invoiced, line.qty_received, | ||
precision_digits=precision) == -1: | ||
order.invoice_status = 'to invoice' | ||
break | ||
elif float_compare(line.qty_invoiced, line.qty_received, | ||
precision_digits=precision) >= 0: | ||
order.invoice_status = 'invoiced' | ||
break | ||
|
||
@api.depends('state', 'order_line.invoice_status') | ||
def _get_invoiced(self): | ||
""" | ||
Attention! This method overrides the standard method of Odoo. | ||
Compute the invoice status of a PO. Possible statuses: | ||
- no: if the PO is not in status 'purchase' or 'done', we consider that | ||
there is nothing to be billed for. This is also the default value if | ||
the conditions of no other status is met. | ||
- to invoice: if any PO line is 'to invoice', the whole PO is 'to | ||
invoice' | ||
- invoiced: if all PO lines are invoiced, the PO is invoiced. | ||
The invoice_ids are obtained thanks to the invoice lines of the PO | ||
lines, and we also search for possible refunds created directly from | ||
existing invoices. This is necessary since such a | ||
refund is not directly linked to the PO. | ||
""" | ||
for order in self: | ||
line_invoice_status = [line.invoice_status for line in | ||
order.order_line] | ||
|
||
if order.state not in ('purchase', 'done'): | ||
invoice_status = 'no' | ||
elif any(invoice_status == 'to invoice' | ||
for invoice_status in line_invoice_status): | ||
invoice_status = 'to invoice' | ||
elif all(invoice_status == 'invoiced' | ||
for invoice_status in line_invoice_status): | ||
invoice_status = 'invoiced' | ||
else: | ||
invoice_status = 'no' | ||
|
||
order.invoice_status = invoice_status | ||
|
||
|
||
class PurchaseOrderLine(models.Model): | ||
_inherit = "purchase.order.line" | ||
|
||
@api.depends('invoice_lines.invoice_id.state', | ||
'invoice_lines.invoice_id.type') | ||
def _compute_qty_invoiced(self): | ||
""" | ||
Attention! This method overrides the standard method of Odoo. | ||
""" | ||
for line in self: | ||
qty = 0.0 | ||
for inv_line in line.invoice_lines: | ||
if inv_line.invoice_id.state not in ['cancel']: | ||
inv_qty = inv_line.uom_id._compute_qty_obj( | ||
inv_line.uom_id, inv_line.quantity, line.product_uom) | ||
if inv_line.invoice_id.type == 'in_invoice': | ||
qty += inv_qty | ||
else: | ||
qty -= inv_qty | ||
line.qty_invoiced = qty | ||
|
||
@api.depends('product_qty', 'qty_received', 'qty_to_invoice', | ||
'qty_invoiced', 'order_id.state') | ||
def _compute_invoice_status(self): | ||
""" | ||
Compute the invoice status of a PO line. Possible statuses: | ||
- no: if the PO is not in status 'purchase' or 'done', we consider that | ||
there is nothing to be billed for. This is also the default value if | ||
the conditions of no other status is met. | ||
- to invoice: we refer to the quantity to invoice of the line. | ||
Refer to method `_compute_qty_to_invoice()` for more information on | ||
how this quantity is calculated. | ||
- invoiced: the quantity invoiced is larger or equal to the quantity | ||
ordered. | ||
""" | ||
precision = self.env['decimal.precision'].precision_get( | ||
'Product Unit of Measure') | ||
for line in self: | ||
if line.state not in ('purchase', 'done'): | ||
line.invoice_status = 'no' | ||
elif line.state == 'done': | ||
if float_is_zero(line.qty_invoiced, | ||
precision_digits=precision): | ||
line.invoice_status = 'no' | ||
else: | ||
line.invoice_status = 'invoiced' | ||
elif not float_is_zero(line.qty_to_invoice, | ||
precision_digits=precision): | ||
line.invoice_status = 'to invoice' | ||
elif float_compare(line.qty_invoiced, line.product_qty, | ||
precision_digits=precision) >= 0: | ||
line.invoice_status = 'invoiced' | ||
else: | ||
line.invoice_status = 'no' | ||
|
||
@api.depends('qty_invoiced', 'qty_received', 'product_qty', | ||
'order_id.state') | ||
def _compute_qty_to_invoice(self): | ||
""" | ||
Compute the quantity to be billed. If the Control Purchase Bills is | ||
in ordered quantities, the quantity to invoice is | ||
calculated from the ordered quantity. Otherwise, the quantity | ||
received is used. | ||
""" | ||
for line in self: | ||
if line.order_id.state == 'purchase': | ||
if line.product_id.purchase_method == 'purchase': | ||
line.qty_to_invoice = line.product_qty - \ | ||
line.qty_invoiced | ||
else: | ||
line.qty_to_invoice = line.qty_received - line.qty_invoiced | ||
else: | ||
line.qty_to_invoice = 0 | ||
|
||
invoice_status = fields.Selection([ | ||
('no', 'Not purchased'), | ||
('to invoice', 'Waiting Invoices'), | ||
('invoiced', 'Invoice Received'), | ||
], string='Invoice Status', compute='_compute_invoice_status', | ||
store=True, readonly=True, copy=False, default='no') | ||
|
||
qty_to_invoice = fields.Float(compute='_compute_qty_to_invoice', | ||
string="To Be Billed Qty", store=True) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<record id="purchase_order_form" model="ir.ui.view"> | ||
<field name="name">purchase.order.form</field> | ||
<field name="model">purchase.order</field> | ||
<field name="inherit_id" ref="purchase.purchase_order_form"/> | ||
<field name="arch" type="xml"> | ||
<field name="invoice_count" position="attributes"> | ||
<attribute name="string">Invoices & Refunds</attribute> | ||
</field> | ||
<xpath expr="//field[@name='order_line']/tree/field[@name='qty_invoiced']" | ||
position="before"> | ||
<field name="qty_to_invoice" | ||
invisible="not context.get('show_purchase', False)"/> | ||
<field name="invoice_status" | ||
invisible="not context.get('show_purchase', False)"/> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |
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,70 @@ | ||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
|
||
=============== | ||
Purchase Return | ||
=============== | ||
|
||
This module adds the possibility to create and process Return Purchase Orders. | ||
|
||
These are orders that users can create to process the return of items to a | ||
vendor. | ||
|
||
* A return PO can be created with or without reference to an existing PO. | ||
|
||
* Once a return PO is confirmed, an outbound picking is created, so as to | ||
ship the products back to the vendor. | ||
|
||
* A user can create a refund bill referencing a return PO. | ||
|
||
|
||
Usage | ||
===== | ||
|
||
Pending | ||
|
||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
:alt: Try me on Runbot | ||
:target: https://runbot.odoo-community.org/runbot/142/9.0 | ||
|
||
Known issues / Roadmap | ||
====================== | ||
|
||
* Pending | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues | ||
<https://github.com/OCA/purchase-workflow/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. | ||
|
||
Credits | ||
======= | ||
|
||
Images | ||
------ | ||
|
||
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. | ||
|
||
Contributors | ||
------------ | ||
|
||
* Jordi Ballester Alomar <jordi.ballester@eficent.com> | ||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://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 https://odoo-community.org. |
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,6 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import models | ||
from . import wizards |
Oops, something went wrong.