Skip to content

Commit

Permalink
[MIG] sale_invoice_plan: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TheerayutEncoder committed Dec 6, 2024
1 parent 65f797c commit bebe744
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 44 deletions.
10 changes: 5 additions & 5 deletions sale_invoice_plan/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -80,7 +80,7 @@ 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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_invoice_plan%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_invoice_plan%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -126,6 +126,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-kittiu|

This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/15.0/sale_invoice_plan>`_ project on GitHub.
This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/16.0/sale_invoice_plan>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion sale_invoice_plan/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 8 additions & 9 deletions sale_invoice_plan/models/sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
12 changes: 8 additions & 4 deletions sale_invoice_plan/models/sale_invoice_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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(
Expand Down Expand Up @@ -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"
Expand All @@ -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"""
Expand Down
17 changes: 10 additions & 7 deletions sale_invoice_plan/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
: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.
Expand Down Expand Up @@ -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 }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -368,7 +369,7 @@ <h1 class="title">Sales Invoice Plan</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:09c96dddef2659c83a39fc88dc4ff76d555da27304bfcf1e9ba82d7639831bb7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/sale-workflow/tree/15.0/sale_invoice_plan"><img alt="OCA/sale-workflow" src="https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/sale-workflow-15-0/sale-workflow-15-0-sale_invoice_plan"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/sale-workflow/tree/16.0/sale_invoice_plan"><img alt="OCA/sale-workflow" src="https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/sale-workflow-16-0/sale-workflow-16-0-sale_invoice_plan"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>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.
Expand Down Expand Up @@ -435,7 +436,7 @@ <h1><a class="toc-backref" href="#toc-entry-6">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/sale-workflow/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_invoice_plan%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_invoice_plan%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -467,13 +468,15 @@ <h2><a class="toc-backref" href="#toc-entry-10">Other credits</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-11">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>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.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/kittiu"><img alt="kittiu" src="https://github.com/kittiu.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/sale-workflow/tree/15.0/sale_invoice_plan">OCA/sale-workflow</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/sale-workflow/tree/16.0/sale_invoice_plan">OCA/sale-workflow</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
17 changes: 8 additions & 9 deletions sale_invoice_plan/tests/test_sale_invoice_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
)
Expand Down Expand Up @@ -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
Expand Down
28 changes: 21 additions & 7 deletions sale_invoice_plan/views/sale_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,34 +159,48 @@
name="sales"
domain="[('state', 'in', ('sale','done'))]"
/>
<filter
string="Not Invoiced"
name="not_invoiced"
domain="[('state', 'in', ('sale','done')), ('invoiced', '=', False)]"
/>
<filter
string="Not Invoiced &amp; Due"
name="over_plan_date"
domain="[
('state', 'in', ('sale','done')),
('invoiced', '=', False),
('plan_date', '&lt;=', context_today().strftime('%Y-%m-%d'))
]"
/>
<group expand="0" string="Group By">
<filter
string="Customer"
name="customer"
name="groupby_customer"
domain="[]"
context="{'group_by':'partner_id'}"
/>
<filter
string="Sales Order"
name="sale"
name="groupby_sale"
domain="[]"
context="{'group_by':'sale_id'}"
/>
<filter
string="Analytic Account"
name="analytic_account_id"
name="groupby_analytic_account_id"
domain="[]"
context="{'group_by':'analytic_account_id'}"
/>
<filter
string="Installment"
name="install"
name="groupby_install"
domain="[]"
context="{'group_by':'installment'}"
/>
<filter
string="Status"
name="state"
name="groupby_state"
domain="[]"
context="{'group_by':'state'}"
/>
Expand Down Expand Up @@ -222,7 +236,7 @@
<field name="search_view_id" ref="view_sale_invoice_plan_filter" />
<field
name="context"
>{'search_default_draft': 1, 'search_default_sale': 1}</field>
>{'search_default_sales': 1, 'search_default_groupby_sale': 1}</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
View sales invoice plan lines
Expand All @@ -237,6 +251,6 @@
id="menu_sale_invoice_plan"
parent="sale.sale_order_menu"
groups="sales_team.group_sale_salesman"
sequence="2"
sequence="25"
/>
</odoo>
4 changes: 2 additions & 2 deletions sale_invoice_plan/wizard/sale_make_invoice_advance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bebe744

Please sign in to comment.