-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[9.0][ADD] module 'sale_force_invoiced' (#439)
* [ADD] module 'sale_force_invoiced' for 9.0 * [FIX] Travis
- Loading branch information
1 parent
4b9639f
commit 6fd418e
Showing
9 changed files
with
254 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,74 @@ | ||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg | ||
:alt: License: AGPL-3 | ||
|
||
=================== | ||
Sale Force Invoiced | ||
=================== | ||
|
||
This module adds the possibility for users to force the invoice status of the | ||
sales orders to 'Invoiced', even when not all the quantities ordered or | ||
delivered have been invoiced. | ||
|
||
This feature useful in the following scenario: | ||
|
||
* The customer disputes the quantities to be invoiced for, after the | ||
products have been delivered to her/him, and you agree to reduce the | ||
quantity to invoice (without sending a refund). | ||
|
||
* When migrating from a previous Odoo version, in some cases there is less | ||
quantity invoiced to what was delivered, and you don't want these old sales | ||
orders to appear in your 'To Invoice' list. | ||
|
||
|
||
Usage | ||
===== | ||
|
||
#. Create a sales order and confirm it. | ||
#. Deliver the products/services. | ||
#. Create an invoice and reduce the invoiced quantity. The sales order | ||
invoicing status is 'To Invoice'. | ||
#. Change the status of the sales order to 'Done'. | ||
#. Check the field 'Force Invoiced' | ||
|
||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
:alt: Try me on Runbot | ||
:target: https://runbot.odoo-community.org/runbot/167/9.0 | ||
|
||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-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 <[email protected]> | ||
|
||
|
||
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,5 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2017 Eficent Business and IT Consulting Services S.L. | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import model |
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 -*- | ||
# © 2017 Eficent Business and IT Consulting Services S.L. | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
{ | ||
'name': 'Sale Force Invoiced', | ||
'summary': 'Allows to force the invoice status of the sales order to ' | ||
'Invoiced', | ||
'version': '9.0.1.0.0', | ||
"author": "Eficent," | ||
"Odoo Community Association (OCA)", | ||
'category': 'sale', | ||
'license': 'AGPL-3', | ||
'website': "https://github.com/OCA/sale-workflow", | ||
'depends': ['sale'], | ||
'data': [ | ||
'view/sale_view.xml' | ||
], | ||
'installable': True, | ||
} |
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,5 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2017 Eficent Business and IT Consulting Services S.L. | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import sale_order |
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,26 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2017 Eficent Business and IT Consulting Services S.L. | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from openerp import api, fields, models | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = 'sale.order' | ||
|
||
force_invoiced = fields.Boolean(string='Force invoiced', | ||
help='When you set this field, the sales ' | ||
'order will be considered as fully ' | ||
'invoiced, even when there may be ' | ||
'ordered or delivered quantities ' | ||
'pending to invoice.', | ||
readonly=True, | ||
states={'done': [('readonly', False)]}, | ||
default=False) | ||
|
||
@api.depends('force_invoiced') | ||
def _get_invoiced(self): | ||
super(SaleOrder, self)._get_invoiced() | ||
for order in self: | ||
if order.force_invoiced and order.invoice_status == 'to invoice': | ||
order.invoice_status = 'invoiced' |
Loading
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,5 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2017 Eficent Business and IT Consulting Services S.L. | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import test_sale_force_invoiced |
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,104 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2017 Eficent Business and IT Consulting Services S.L. | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from openerp.tests.common import TransactionCase | ||
|
||
|
||
class TestSaleForceInvoiced(TransactionCase): | ||
|
||
def setUp(self): | ||
super(TestSaleForceInvoiced, self).setUp() | ||
self.sale_order_model = self.env['sale.order'] | ||
self.sale_order_line_model = self.env['sale.order.line'] | ||
|
||
# Data | ||
product_ctg = self._create_product_category() | ||
self.service_1 = self._create_product('test_product1', | ||
product_ctg) | ||
self.service_2 = self._create_product('test_product2', | ||
product_ctg) | ||
self.customer = self._create_customer('Test Customer') | ||
|
||
def _create_customer(self, name): | ||
"""Create a Partner.""" | ||
return self.env['res.partner'].create({ | ||
'name': name, | ||
'email': '[email protected]', | ||
'customer': True, | ||
'phone': 123456, | ||
}) | ||
|
||
def _create_product_category(self): | ||
product_ctg = self.env['product.category'].create({ | ||
'name': 'test_product_ctg', | ||
}) | ||
return product_ctg | ||
|
||
def _create_product(self, name, product_ctg): | ||
product = self.env['product.product'].create({ | ||
'name': name, | ||
'categ_id': product_ctg.id, | ||
'type': 'service', | ||
'invoice_policy': 'order', | ||
'track_service': 'manual' | ||
}) | ||
return product | ||
|
||
def _create_invoice_from_sale(self, sale): | ||
payment = self.env['sale.advance.payment.inv'].create({ | ||
'advance_payment_method': 'delivered' | ||
}) | ||
sale_context = { | ||
'active_id': sale.id, | ||
'active_ids': sale.ids, | ||
'active_model': 'sale.order', | ||
'open_invoices': True, | ||
} | ||
res = payment.with_context(sale_context).create_invoices() | ||
invoice_id = res['res_id'] | ||
return invoice_id | ||
|
||
def test_sales_order(self): | ||
so = self.sale_order_model.create({ | ||
'partner_id': self.customer.id, | ||
}) | ||
sol1 = self.sale_order_line_model.create({ | ||
'product_id': self.service_1.id, | ||
'product_uom_qty': 1, | ||
'order_id': so.id | ||
}) | ||
sol2 = self.sale_order_line_model.create({ | ||
'product_id': self.service_2.id, | ||
'product_uom_qty': 2, | ||
'order_id': so.id | ||
}) | ||
|
||
# confirm quotation | ||
so.action_confirm() | ||
# update quantities delivered | ||
sol1.qty_delivered = 1 | ||
sol2.qty_delivered = 2 | ||
|
||
self.assertEquals(so.invoice_status, 'to invoice', | ||
"The invoice status should be To Invoice") | ||
|
||
self._create_invoice_from_sale(so) | ||
self.assertEquals(so.invoice_status, 'invoiced', | ||
"The invoice status should be Invoiced") | ||
|
||
# Reduce the invoiced qty | ||
for line in sol2.invoice_lines: | ||
line.quantity = 1 | ||
|
||
self.assertEquals(so.invoice_status, 'to invoice', | ||
"The invoice status should be To Invoice") | ||
|
||
so.action_done() | ||
so.force_invoiced = True | ||
self.assertEquals(so.invoice_status, 'invoiced', | ||
"The invoice status should be Invoiced") | ||
|
||
so.force_invoiced = False | ||
self.assertEquals(so.invoice_status, 'to invoice', | ||
"The invoice status should be To 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,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<openerp> | ||
|
||
<record id="view_order_form" model="ir.ui.view"> | ||
<field name="name">sale.order.form</field> | ||
<field name="model">sale.order</field> | ||
<field name="inherit_id" ref="sale.view_order_form"/> | ||
<field name="arch" type="xml"> | ||
<group name="sale_pay" position="inside"> | ||
<field name="force_invoiced" groups="base.group_sale_manager"/> | ||
</group> | ||
</field> | ||
</record> | ||
|
||
</openerp> |