From bebe7444109cae933925c793a944e87517b692df Mon Sep 17 00:00:00 2001
From: theerayut
Date: Fri, 6 Dec 2024 15:19:33 +0700
Subject: [PATCH] [MIG] sale_invoice_plan: Migration to 16.0
---
sale_invoice_plan/README.rst | 10 +++----
sale_invoice_plan/__manifest__.py | 2 +-
sale_invoice_plan/models/sale.py | 17 ++++++-----
sale_invoice_plan/models/sale_invoice_plan.py | 12 +++++---
.../static/description/index.html | 17 ++++++-----
.../tests/test_sale_invoice_plan.py | 17 ++++++-----
sale_invoice_plan/views/sale_view.xml | 28 ++++++++++++++-----
.../wizard/sale_make_invoice_advance.py | 4 +--
8 files changed, 63 insertions(+), 44 deletions(-)
diff --git a/sale_invoice_plan/README.rst b/sale_invoice_plan/README.rst
index 368d779b2b5..465302699bf 100644
--- a/sale_invoice_plan/README.rst
+++ b/sale_invoice_plan/README.rst
@@ -17,13 +17,13 @@ Sales Invoice Plan
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github
- :target: https://github.com/OCA/sale-workflow/tree/15.0/sale_invoice_plan
+ :target: https://github.com/OCA/sale-workflow/tree/16.0/sale_invoice_plan
:alt: OCA/sale-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
- :target: https://translation.odoo-community.org/projects/sale-workflow-15-0/sale-workflow-15-0-sale_invoice_plan
+ :target: https://translation.odoo-community.org/projects/sale-workflow-16-0/sale-workflow-16-0-sale_invoice_plan
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
- :target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=15.0
+ :target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=16.0
:alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -80,7 +80,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues `_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
-`feedback `_.
+`feedback `_.
Do not contact contributors directly about support or help with technical issues.
@@ -126,6 +126,6 @@ Current `maintainer `__:
|maintainer-kittiu|
-This module is part of the `OCA/sale-workflow `_ project on GitHub.
+This module is part of the `OCA/sale-workflow `_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/sale_invoice_plan/__manifest__.py b/sale_invoice_plan/__manifest__.py
index e6b71871ee7..38947e2ec10 100644
--- a/sale_invoice_plan/__manifest__.py
+++ b/sale_invoice_plan/__manifest__.py
@@ -4,7 +4,7 @@
{
"name": "Sales Invoice Plan",
"summary": "Add to sales order, ability to manage future invoice plan",
- "version": "15.0.1.4.2",
+ "version": "16.0.1.0.0",
"author": "Ecosoft,Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/sale-workflow",
diff --git a/sale_invoice_plan/models/sale.py b/sale_invoice_plan/models/sale.py
index dc9b32c8e8b..6b4096a8750 100644
--- a/sale_invoice_plan/models/sale.py
+++ b/sale_invoice_plan/models/sale.py
@@ -45,14 +45,13 @@ def _compute_invoice_plan_process(self):
for rec in self:
has_invoice_plan = rec.use_invoice_plan and rec.invoice_plan_ids
to_invoice = rec.invoice_plan_ids.filtered(lambda l: not l.invoiced)
- if rec.state == "sale" and has_invoice_plan and to_invoice:
- if rec.invoice_status == "to invoice" or (
- rec.invoice_status == "no"
- and "advance" in to_invoice.mapped("invoice_type")
- ):
- rec.invoice_plan_process = True
- continue
- rec.invoice_plan_process = False
+ inv_or_adv = rec.invoice_status == "to invoice" or (
+ rec.invoice_status == "no"
+ and "advance" in to_invoice.mapped("invoice_type")
+ )
+ rec.invoice_plan_process = (
+ rec.state == "sale" and has_invoice_plan and to_invoice and inv_or_adv
+ )
@api.constrains("invoice_plan_ids")
def _check_invoice_plan_total_percent(self):
@@ -141,6 +140,6 @@ def _create_invoices(self, grouped=False, final=False, date=None):
for move in moves:
plan._compute_new_invoice_quantity(move)
move.invoice_date = plan.plan_date
- move._onchange_invoice_date()
+ move._compute_date()
plan.invoice_move_ids += moves
return moves
diff --git a/sale_invoice_plan/models/sale_invoice_plan.py b/sale_invoice_plan/models/sale_invoice_plan.py
index 3ff4100ebd5..ae90f2257a2 100644
--- a/sale_invoice_plan/models/sale_invoice_plan.py
+++ b/sale_invoice_plan/models/sale_invoice_plan.py
@@ -60,7 +60,7 @@ class SaleInvoicePlan(models.Model):
string="Invoices",
readonly=True,
)
- amount_invoiced = fields.Float(compute="_compute_invoiced")
+ amount_invoiced = fields.Float(compute="_compute_invoiced", store=True)
to_invoice = fields.Boolean(
string="Next Invoice",
compute="_compute_to_invoice",
@@ -69,6 +69,7 @@ class SaleInvoicePlan(models.Model):
invoiced = fields.Boolean(
string="Invoice Created",
compute="_compute_invoiced",
+ store=True,
help="If this line already invoiced",
)
no_edit = fields.Boolean(
@@ -153,12 +154,13 @@ def _get_amount_invoice(self, invoices):
amount_invoiced = sum(lines.mapped("price_subtotal"))
return amount_invoiced
+ @api.depends("invoice_move_ids.state")
def _compute_invoiced(self):
for rec in self:
invoiced = rec.invoice_move_ids.filtered(
lambda l: l.state in ("draft", "posted")
)
- rec.invoiced = invoiced and True or False
+ rec.invoiced = True if invoiced else False
rec.amount_invoiced = (
sum(invoiced.mapped("amount_untaxed"))
if rec.invoice_type == "advance"
@@ -178,8 +180,10 @@ def _compute_new_invoice_quantity(self, invoice_move):
move = invoice_move.with_context(check_move_validity=False)
for line in move.invoice_line_ids:
self._update_new_quantity(line, percent)
- move.line_ids.filtered("exclude_from_invoice_tab").unlink()
- move._move_autocomplete_invoice_lines_values() # recompute dr/cr
+ move.line_ids.filtered(
+ lambda x: x.display_type
+ not in ("product", "line_section", "line_note", "payment_term", "tax")
+ ).unlink()
def _update_new_quantity(self, line, percent):
"""Hook function"""
diff --git a/sale_invoice_plan/static/description/index.html b/sale_invoice_plan/static/description/index.html
index 5b4b4cc6ea5..ff86896f271 100644
--- a/sale_invoice_plan/static/description/index.html
+++ b/sale_invoice_plan/static/description/index.html
@@ -8,10 +8,11 @@
/*
:Author: David Goodger (goodger@python.org)
-:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
+:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
+Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
@@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }
-pre.code .ln { color: grey; } /* line numbers */
+pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -300,7 +301,7 @@
span.pre {
white-space: pre }
-span.problematic {
+span.problematic, pre.problematic {
color: red }
span.section-subtitle {
@@ -368,7 +369,7 @@ Sales Invoice Plan
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:09c96dddef2659c83a39fc88dc4ff76d555da27304bfcf1e9ba82d7639831bb7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-
+
By standard feature, user can gradually create partial invoices, one by one.
This module add ability to create invoices based on the predefined invoice plan,
either all at once, or one by one.
@@ -435,7 +436,7 @@
Bugs are tracked on GitHub Issues.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
-feedback.
+feedback.
Do not contact contributors directly about support or help with technical issues.
@@ -467,13 +468,15 @@
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.
Current maintainer:
-
This module is part of the OCA/sale-workflow project on GitHub.
+
This module is part of the OCA/sale-workflow project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/sale_invoice_plan/tests/test_sale_invoice_plan.py b/sale_invoice_plan/tests/test_sale_invoice_plan.py
index 8597e2e3344..3eca6b68fbf 100644
--- a/sale_invoice_plan/tests/test_sale_invoice_plan.py
+++ b/sale_invoice_plan/tests/test_sale_invoice_plan.py
@@ -22,22 +22,22 @@ def setUpClass(cls):
"mail_create_nolog": True,
}
- # Create base account to simulate a chart of account
- user_type_payable = cls.env.ref("account.data_account_type_payable")
+ # Create base account to simulate a chart of account for payable account
+ user_type_payable = cls.company_data["default_account_payable"]
cls.account_payable = cls.env["account.account"].create(
{
"code": "NC1110",
"name": "Test Payable Account",
- "user_type_id": user_type_payable.id,
+ "account_type": user_type_payable.account_type,
"reconcile": True,
}
)
- user_type_receivable = cls.env.ref("account.data_account_type_receivable")
+ # Create base account to simulate a chart of account for receivable account
cls.account_receivable = cls.env["account.account"].create(
{
"code": "NC1111",
"name": "Test Receivable Account",
- "user_type_id": user_type_receivable.id,
+ "account_type": "asset_receivable",
"reconcile": True,
}
)
@@ -92,12 +92,11 @@ def setUpClass(cls):
@classmethod
def setUpClassicProducts(cls):
# Create an expense journal
- user_type_income = cls.env.ref("account.data_account_type_direct_costs")
cls.account_income_product = cls.env["account.account"].create(
{
- "code": "INCOME_PROD111",
- "name": "Icome - Test Account",
- "user_type_id": user_type_income.id,
+ "code": "4.0.0.0.0",
+ "name": "Income - Test Account",
+ "account_type": "income",
}
)
# Create category
diff --git a/sale_invoice_plan/views/sale_view.xml b/sale_invoice_plan/views/sale_view.xml
index 202c1924cc6..d313593299e 100644
--- a/sale_invoice_plan/views/sale_view.xml
+++ b/sale_invoice_plan/views/sale_view.xml
@@ -159,34 +159,48 @@
name="sales"
domain="[('state', 'in', ('sale','done'))]"
/>
+
+
@@ -222,7 +236,7 @@
{'search_default_draft': 1, 'search_default_sale': 1}
+ >{'search_default_sales': 1, 'search_default_groupby_sale': 1}
View sales invoice plan lines
@@ -237,6 +251,6 @@
id="menu_sale_invoice_plan"
parent="sale.sale_order_menu"
groups="sales_team.group_sale_salesman"
- sequence="2"
+ sequence="25"
/>
diff --git a/sale_invoice_plan/wizard/sale_make_invoice_advance.py b/sale_invoice_plan/wizard/sale_make_invoice_advance.py
index 5a0d4da40ba..00b8c1076c0 100644
--- a/sale_invoice_plan/wizard/sale_make_invoice_advance.py
+++ b/sale_invoice_plan/wizard/sale_make_invoice_advance.py
@@ -6,8 +6,8 @@
class SaleAdvancePaymentInv(models.TransientModel):
_inherit = "sale.advance.payment.inv"
- def _create_invoice(self, order, so_line, amount):
- invoice = super()._create_invoice(order, so_line, amount)
+ def _create_invoices(self, sale_orders):
+ invoice = super()._create_invoices(sale_orders)
invoice_plan_id = self._context.get("invoice_plan_id")
if invoice_plan_id:
plan = self.env["sale.invoice.plan"].browse(invoice_plan_id)