Skip to content

Commit

Permalink
[MIG] purchase_force_invoiced to v16
Browse files Browse the repository at this point in the history
Set force_invoiced field invisible on RFQs (state not in purchase or done)
force_invoiced is now tracked in chatter
  • Loading branch information
alexis-via committed Dec 14, 2022
1 parent 6a10b33 commit 294b869
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 28 deletions.
4 changes: 2 additions & 2 deletions purchase_force_invoiced/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"name": "Purchase Force Invoiced",
"summary": "Allows to force the billing status of the purchase order to "
'"Invoiced"',
"version": "15.0.1.0.1",
"version": "16.0.1.0.0",
"author": "Forgeflow, Odoo Community Association (OCA)",
"category": "Purchase Management",
"license": "AGPL-3",
"website": "https://github.com/OCA/purchase-workflow",
"depends": ["purchase"],
"data": ["view/purchase_view.xml"],
"data": ["view/purchase_order.xml"],
"installable": True,
}
2 changes: 1 addition & 1 deletion purchase_force_invoiced/model/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from . import purchase
from . import purchase_order
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class PurchaseOrder(models.Model):
readonly=True,
states={"done": [("readonly", False)]},
copy=False,
tracking=True,
help="When you set this field, the purchase order will be "
"considered as fully billed, even when there may be ordered "
"or delivered quantities pending to bill. To use this field, "
Expand All @@ -18,7 +19,7 @@ class PurchaseOrder(models.Model):

@api.depends("force_invoiced")
def _get_invoiced(self):
res = super(PurchaseOrder, self)._get_invoiced()
res = super()._get_invoiced()
for order in self.filtered(
lambda po: po.force_invoiced and po.invoice_status == "to invoice"
):
Expand Down
36 changes: 13 additions & 23 deletions purchase_force_invoiced/tests/test_purchase_force_invoiced.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from odoo import fields
from odoo.tests import tagged
from odoo.tests.common import TransactionCase


@tagged("post_install", "-at_install")
class TestPurchaseForceInvoiced(TransactionCase):
def setUp(self):
super(TestPurchaseForceInvoiced, self).setUp()
Expand All @@ -15,11 +17,7 @@ def setUp(self):
self.account_invoice_line = self.env["account.move.line"]
self.invoice_account = self.env["account.account"].search(
[
(
"user_type_id",
"=",
self.env.ref("account.data_account_type_revenue").id,
),
("account_type", "=", "expense"),
("company_id", "=", self.env.company.id),
],
limit=1,
Expand Down Expand Up @@ -52,21 +50,13 @@ def _create_product(self, name, product_ctg):
)
return product

def _create_invoice_from_purchase(self, purchase):
invoice = self.account_invoice_model.create(
{"partner_id": purchase.partner_id.id, "move_type": "in_invoice"}
)
invoice.write({"purchase_id": purchase.id})
invoice._onchange_purchase_auto_complete()

return invoice

def create_invoice_line(self, line, invoice):
vals = [
(
0,
0,
{
"display_type": "product",
"name": line.name,
"product_id": line.product_id.id,
"quantity": line.qty_received - line.qty_invoiced,
Expand Down Expand Up @@ -113,13 +103,11 @@ def test_purchase_order(self):
po.invoice_status, "to invoice", "The invoice status should be To Invoice"
)

invoice = self._create_invoice_from_purchase(po)
self.create_invoice_line(pol1, invoice)
self.create_invoice_line(pol2, invoice)
action = po.action_create_invoice()
invoice = self.env["account.move"].browse(action["res_id"])
self.assertEqual(
po.invoice_status, "invoiced", "The invoice status should be Invoiced"
)

# Reduce the invoiced qty
for line in pol2.invoice_lines:
line.with_context(check_move_validity=False).unlink()
Expand All @@ -132,14 +120,16 @@ def test_purchase_order(self):
self.assertEqual(
po.invoice_status, "invoiced", "The invoice status should be Invoiced"
)
invoice = self._create_invoice_from_purchase(po)
invoice_qty = sum(invoice.mapped("invoice_line_ids.quantity"))
self.assertEqual(invoice_qty, 0.0)
# We remove the force invoiced.
po.force_invoiced = False
self.assertEqual(
po.invoice_status, "to invoice", "The invoice status should be To Invoice"
)
self.create_invoice_line(pol2, invoice)
invoice_qty = sum(invoice.mapped("invoice_line_ids.quantity"))
action = po.action_create_invoice()
invoice = self.env["account.move"].browse(action["res_id"])
invoice_qty = sum(
invoice.invoice_line_ids.filtered(
lambda x: x.product_id.id == self.service_2.id
).mapped("quantity")
)
self.assertEqual(invoice_qty, 2.0)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
<field name="inherit_id" ref="purchase.purchase_order_form" />
<field name="arch" type="xml">
<field name="invoice_status" position="after">
<field name="force_invoiced" groups="purchase.group_purchase_manager" />
<field
name="force_invoiced"
groups="purchase.group_purchase_manager"
attrs="{'invisible': [('state', 'not in', ('purchase', 'done'))]}"
widget="boolean_toggle"
/>
</field>
</field>
</record>
Expand Down
6 changes: 6 additions & 0 deletions setup/purchase_force_invoiced/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 294b869

Please sign in to comment.