Skip to content

Commit

Permalink
[MIG] purchase_invoice_plan: Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SurachetS authored and AungKoKoLin1997 committed Sep 15, 2023
1 parent c9ff986 commit a33d264
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion purchase_invoice_plan/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Purchase Invoice Plan",
"summary": "Add to purchases order, ability to manage future invoice plan",
"version": "13.0.1.0.0",
"version": "14.0.1.0.0",
"author": "Ecosoft,Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/purchase-workflow",
Expand Down
20 changes: 9 additions & 11 deletions purchase_invoice_plan/models/purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,15 @@ def action_invoice_create(self):
journal = (
self.env["account.move"]
.with_context(
default_type="in_invoice", default_currency_id=self.currency_id.id
default_type="in_invoice",
default_currency_id=self.currency_id.id,
default_company_id=self.env.user.company_id.id,
)
._get_default_journal()
)
pre_inv = self.env["account.move"].new(
{
"type": "in_invoice",
"move_type": "in_invoice",
"purchase_id": self.id,
"journal_id": journal.id,
"currency_id": self.currency_id.id,
Expand Down Expand Up @@ -139,7 +141,7 @@ def action_invoice_create(self):
if invoice_plan_id:
plan = self.env["purchase.invoice.plan"].browse(invoice_plan_id)
plan._compute_new_invoice_quantity(invoice)
invoice.date_invoice = plan.plan_date
invoice.invoice_date = plan.plan_date
plan.invoice_ids += invoice
return invoice

Expand All @@ -164,14 +166,6 @@ class PurchaseInvoicePlan(models.Model):
index=True,
)
state = fields.Selection(
selection=[
("draft", "RFQ"),
("sent", "RFQ Sent"),
("to approve", "To Approve"),
("purchase", "Purchase Order"),
("done", "Locked"),
("cancel", "Cancelled"),
],
string="Status",
related="purchase_id.state",
store=True,
Expand Down Expand Up @@ -207,13 +201,16 @@ class PurchaseInvoicePlan(models.Model):
string="Next Invoice",
compute="_compute_to_invoice",
help="If this line is ready to create new invoice",
store=True,
)
invoiced = fields.Boolean(
string="Invoice Created",
compute="_compute_invoiced",
help="If this line already invoiced",
store=True,
)

@api.depends("purchase_id.state", "purchase_id.invoice_plan_ids.invoiced")
def _compute_to_invoice(self):
"""If any invoice is in draft/open/paid do not allow to create inv
Only if previous to_invoice is False, it is eligible to_invoice
Expand All @@ -227,6 +224,7 @@ def _compute_to_invoice(self):
rec.to_invoice = True
break

@api.depends("invoice_ids.state")
def _compute_invoiced(self):
for rec in self:
invoiced = rec.invoice_ids.filtered(
Expand Down
2 changes: 2 additions & 0 deletions purchase_invoice_plan/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_purchase_invoice_plan,access_purchase_invoice_plan,model_purchase_invoice_plan,,1,1,1,1
access_purchase_create_invoice_plan,access_purchase_create_invoice_plan,model_purchase_create_invoice_plan,,1,1,1,1
access_purchase_make_planned_invoice,access_purchase_make_planned_invoice,model_purchase_make_planned_invoice,,1,1,1,1
8 changes: 4 additions & 4 deletions purchase_invoice_plan/tests/test_purchase_invoice_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_invoice_plan(self):
# Receive all products
receive = self.test_po_product.picking_ids.filtered(lambda l: l.state != "done")
receive.move_ids_without_package.quantity_done = 10.0
receive.action_done()
receive._action_done()
purchase_create = self.env["purchase.make.planned.invoice"].create({})
purchase_create.with_context(ctx).create_invoices_by_plan()

Expand Down Expand Up @@ -105,7 +105,7 @@ def test_error(self):
p.num_installment = 0
p.save()
error_message = "Number Installment must greater than 1"
self.assertEqual(e.exception.name, error_message)
self.assertEqual(e.exception.args[0], error_message)
# Create purchase plan
with Form(self.PurchaseInvoicePlan) as p:
p.num_installment = 5
Expand All @@ -116,7 +116,7 @@ def test_error(self):
# Receive product 1 unit
receive = self.test_po_product.picking_ids.filtered(lambda l: l.state != "done")
receive.move_ids_without_package.quantity_done = 1.0
receive.action_done()
receive._action_done()
# ValidationError Create all invoice plan - Receive < Invoice require
purchase_create = self.env["purchase.make.planned.invoice"].create({})
with self.assertRaises(ValidationError) as e:
Expand All @@ -125,4 +125,4 @@ def test_error(self):
"Plan quantity: 2.0, exceed invoiceable quantity: 1.0"
"\nProduct should be delivered before invoice"
)
self.assertEqual(e.exception.name, error_message)
self.assertEqual(e.exception.args[0], error_message)
6 changes: 3 additions & 3 deletions purchase_invoice_plan/views/purchase_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<label for="use_invoice_plan" />
</div>
</xpath>
<xpath expr="//button[@name='action_view_invoice']" position="before">
<xpath expr="//button[@name='action_create_invoice']" position="before">
<field name="ip_invoice_plan" invisible="1" />
<button
name="%(action_view_purchase_make_planned_invoice)d"
Expand Down Expand Up @@ -117,13 +117,13 @@
<filter
name="not_invoiced"
string="Waiting Bills"
domain="[('invoice_status','=', 'to invoice')]"
domain="[('to_invoice','=', True)]"
help="Purchase orders that include lines not invoiced."
/>
<filter
name="invoiced"
string="Bills Received"
domain="[('invoice_status','=', 'invoiced')]"
domain="[('invoiced','=', True)]"
help="Purchase orders that have been invoiced."
/>
<group expand="0" string="Group By">
Expand Down

0 comments on commit a33d264

Please sign in to comment.