Skip to content

Commit

Permalink
[MIG] account_payment_multi_deduction: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Saran440 committed Nov 22, 2024
1 parent e2b5604 commit 3927e93
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 38 deletions.
2 changes: 1 addition & 1 deletion account_payment_multi_deduction/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Payment Register with Multiple Deduction",
"version": "16.0.1.0.0",
"version": "18.0.1.0.0",
"author": "Ecosoft, Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/account-payment",
Expand Down
4 changes: 2 additions & 2 deletions account_payment_multi_deduction/models/account_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ def _update_vals_writeoff(
line_vals[update_key] = write_off_line_vals[0][update_key]
break

def _prepare_move_line_default_vals(self, write_off_line_vals=None):
def _prepare_move_line_default_vals(self, write_off_line_vals=None, force_balance=None):
"""Split amount to multi payment deduction
Concept:
* Process by payment difference 'Mark as fully paid' and keep value is paid
* Process by each deduction and keep value is deduction
* Combine all process and return list
"""
self.ensure_one()
line_vals_list = super()._prepare_move_line_default_vals(write_off_line_vals)
line_vals_list = super()._prepare_move_line_default_vals(write_off_line_vals, force_balance)
# payment difference
if not self.is_multi_deduction and write_off_line_vals:
# update writeoff when edit value in payment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

from odoo import Command, fields
from odoo.exceptions import UserError
from odoo.tests.common import Form, TransactionCase
from odoo.tests.common import TransactionCase
from odoo.tests import Form


class TestPaymentMultiDeduction(TransactionCase):
Expand All @@ -20,14 +21,12 @@ def setUpClass(cls):
cls.account_revenue = cls.env["account.account"].search(
[
("account_type", "=", "income"),
("company_id", "=", cls.env.company.id),
],
limit=1,
)
cls.account_expense = cls.env["account.account"].search(
[
("account_type", "=", "expense"),
("company_id", "=", cls.env.company.id),
],
limit=1,
)
Expand Down
22 changes: 15 additions & 7 deletions account_payment_multi_deduction/wizard/account_payment_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ class AccountPaymentRegister(models.TransientModel):
)
deduct_analytic_distribution = fields.Json()

def _update_vals_deduction(self, moves):
move_lines = moves.mapped("line_ids")
def _update_vals_deduction(self, move_lines):
"""For case `Mark as fully paid`,
Hook this method to update field wizard write-off from move lines"""
analytic = {}
[
analytic.update(item)
Expand All @@ -38,8 +39,9 @@ def _update_vals_deduction(self, moves):
]
self.analytic_distribution = analytic

def _update_vals_multi_deduction(self, moves):
move_lines = moves.mapped("line_ids")
def _update_vals_multi_deduction(self, move_lines):
"""For case `Mark invoice as fully paid (multi deduct)`,
Hook this method to update field wizard deduct from move lines"""
analytic = {}
[
analytic.update(item)
Expand All @@ -51,11 +53,17 @@ def _update_vals_multi_deduction(self, moves):
@api.onchange("payment_difference", "payment_difference_handling")
def _onchange_default_deduction(self):
active_ids = self.env.context.get("active_ids", [])
moves = self.env["account.move"].browse(active_ids)
move_lines = self.env["account.move.line"]
model = self.env.context.get("active_model", False)
if model == "account.move.line":
move_lines = move_lines.browse(active_ids)
elif model == "account.move":
move_lines = self.env["account.move"].browse(active_ids).line_ids

if self.payment_difference_handling == "reconcile":
self._update_vals_deduction(moves)
self._update_vals_deduction(move_lines)
if self.payment_difference_handling == "reconcile_multi_deduct":
self._update_vals_multi_deduction(moves)
self._update_vals_multi_deduction(move_lines)

@api.constrains("deduction_ids", "payment_difference_handling")
def _check_deduction_amount(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,31 @@
<field name="model">account.payment.register</field>
<field name="inherit_id" ref="account.view_account_payment_register_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='writeoff_account_id']" position="after">
<div
attrs="{'invisible': [('payment_difference_handling', '!=', 'reconcile')]}"
groups="analytic.group_analytic_accounting"
>
<label for="analytic_distribution" class="oe_edit_only" />
<field
name="analytic_distribution"
widget="analytic_distribution"
groups="analytic.group_analytic_accounting"
options="{'product_field': 'product_id', 'account_field': 'account_id', 'business_domain': 'expense'}"
/>
<!-- Add analytic_distribution on wizard -->
<xpath expr="//group[@name='group1']/div/div" position="inside">
<div class="o_wrap_field d-flex d-sm-contents flex-column mb-3 mb-sm-0" invisible="payment_difference_handling != 'reconcile'" groups="analytic.group_analytic_accounting">
<div class="o_cell o_wrap_label text-break text-900">
<label for="analytic_distribution" class="oe_edit_only"/>
</div>
<div class="o_cell o_wrap_input text-break">
<field
name="analytic_distribution"
widget="analytic_distribution"
groups="analytic.group_analytic_accounting"
options="{'product_field': 'product_id', 'account_field': 'account_id', 'business_domain': 'expense'}"
/>
</div>
</div>
</xpath>
<xpath
expr="/form/group/group[@name='group3']/div/div"
position="attributes"
>
<attribute
name="attrs"
>{'invisible': [('payment_difference_handling','!=','reconcile')]}</attribute>
<!-- Hide write-off field when selected multi deduction -->
<xpath expr="//group[@name='group1']/div/div" position="attributes">
<attribute name="invisible" separator="or" add="payment_difference_handling != 'reconcile'" />
</xpath>
<xpath expr="/form/group/group[@name='group3']" position="after">
<!-- Add multi deduction -->
<xpath expr="//group[@name='group2']" position="after">
<group
colspan="4"
attrs="{'invisible': [('payment_difference_handling', '!=', 'reconcile_multi_deduct')]}"
invisible="payment_difference_handling != 'reconcile_multi_deduct'"
>
<field name="deduct_residual" invisible="1" />
<field name="deduct_analytic_distribution" invisible="1" />
Expand All @@ -39,12 +38,12 @@
colspan="2"
context="{'default_amount': deduct_residual, 'default_analytic_distribution': deduct_analytic_distribution}"
>
<tree editable="bottom">
<field name="currency_id" invisible="1" />
<list editable="bottom">
<field name="currency_id" column_invisible="1" />
<field name="is_open" />
<field
name="account_id"
attrs="{'required': [('is_open', '=', False)]}"
required="not is_open"
/>
<field
name="analytic_distribution"
Expand All @@ -54,7 +53,7 @@
/>
<field name="name" />
<field name="amount" sum="Total Deduction" />
</tree>
</list>
</field>
</group>
</xpath>
Expand Down

0 comments on commit 3927e93

Please sign in to comment.