Skip to content

Commit

Permalink
[MIG] Account payment group: Migration to 16
Browse files Browse the repository at this point in the history
  • Loading branch information
filoquin committed Nov 3, 2022
1 parent e0d50c1 commit cf0b580
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 16 deletions.
9 changes: 5 additions & 4 deletions account_payment_group/models/account_move.py
Expand Up @@ -51,12 +51,13 @@ def _compute_payment_groups(self):
for rec in self:
rec.payment_group_ids = rec._get_reconciled_payments().mapped('payment_group_id')

@api.depends('line_ids.account_id.internal_type', 'line_ids.reconciled')

@api.depends('line_ids.account_id.account_type', 'line_ids.reconciled')
def _compute_open_move_lines(self):
for rec in self:
rec.open_move_line_ids = rec.line_ids.filtered(
lambda r: not r.reconciled and r.account_id.internal_type in (
'payable', 'receivable'))
lambda r: not r.reconciled and r.account_id.account_type in ['asset_receivable','liability_payable'])


def action_register_payment_group(self):
to_pay_move_lines = self.open_move_line_ids
Expand All @@ -73,7 +74,7 @@ def action_register_payment_group(self):
'target': 'current',
'type': 'ir.actions.act_window',
'context': {
'default_partner_type': 'customer' if to_pay_move_lines[0].account_id.internal_type == 'receivable' else 'supplier',
'default_partner_type': 'customer' if to_pay_move_lines[0].account_id.account_type == 'asset_receivable' else 'supplier',
'default_partner_id': to_pay_partners.id,
'default_to_pay_move_line_ids': to_pay_move_lines.ids,
# We set this because if became from other view and in the context has 'create=False'
Expand Down
3 changes: 1 addition & 2 deletions account_payment_group/models/account_move_line.py
Expand Up @@ -31,8 +31,7 @@ def _compute_payment_group_matched_amount(self):
self.payment_group_matched_amount = 0.0
return False
payments = self.env['account.payment.group'].browse(payment_group_id).payment_ids
payment_lines = payments.mapped('line_ids').filtered(lambda x: x.account_internal_type in ['receivable', 'payable'])

payment_lines = payments.mapped('line_ids').filtered(lambda x: x.account_type in ['asset_receivable', 'liability_payable'])
for rec in self:
debit_move_amount = sum(payment_lines.mapped('matched_debit_ids').filtered(lambda x: x.debit_move_id == rec).mapped('amount'))
credit_move_amount = sum(payment_lines.mapped('matched_credit_ids').filtered(lambda x: x.credit_move_id == rec).mapped('amount'))
Expand Down
3 changes: 3 additions & 0 deletions account_payment_group/models/account_payment.py
Expand Up @@ -72,6 +72,8 @@ def _compute_available_journal_ids(self):
filtered_domain.append(('company_id', '=', pay.payment_group_id.company_id.id))
pay.available_journal_ids = journals.filtered_domain(filtered_domain)



@api.depends('payment_method_id')
def _compute_payment_method_description(self):
for rec in self:
Expand Down Expand Up @@ -125,6 +127,7 @@ def _compute_exchange_rate(self):
# rouding odoo believes amount has changed)
@api.onchange('amount_company_currency')
def _inverse_amount_company_currency(self):

for rec in self:
if rec.other_currency and rec.amount_company_currency != \
rec.currency_id._convert(
Expand Down
6 changes: 3 additions & 3 deletions account_payment_group/models/account_payment_group.py
Expand Up @@ -319,7 +319,7 @@ def _compute_matched_move_line_ids(self):
al revz (debit_move_id vs credit_move_id)
"""
for rec in self:
payment_lines = rec.payment_ids.mapped('line_ids').filtered(lambda x: x.account_internal_type in ['receivable', 'payable'])
payment_lines = rec.payment_ids.mapped('line_ids').filtered(lambda x: x.account_type in ['asset_receivable', 'liability_payable'])
rec.matched_move_line_ids = (payment_lines.mapped('matched_debit_ids.debit_move_id') | payment_lines.mapped('matched_credit_ids.credit_move_id')) - payment_lines

@api.depends('payment_ids.line_ids')
Expand Down Expand Up @@ -368,7 +368,7 @@ def _get_to_pay_move_lines_domain(self):
('partner_id.commercial_partner_id', '=', self.commercial_partner_id.id),
('company_id', '=', self.company_id.id), ('move_id.state', '=', 'posted'),
('account_id.reconcile', '=', True), ('reconciled', '=', False), ('full_reconcile_id', '=', False),
('account_id.internal_type', '=', 'receivable' if self.partner_type == 'customer' else 'payable'),
('account_id.account_type', '=', 'asset_receivable' if self.partner_type == 'customer' else 'liability_payable'),
]

def add_all(self):
Expand Down Expand Up @@ -482,7 +482,7 @@ def post(self):

if not created_automatically:
counterpart_aml = rec.payment_ids.mapped('line_ids').filtered(
lambda r: not r.reconciled and r.account_id.internal_type in ('payable', 'receivable'))
lambda r: not r.reconciled and r.account_id.account_type in ('liability_payable', 'asset_receivable'))
if counterpart_aml and rec.to_pay_move_line_ids:
(counterpart_aml + (rec.to_pay_move_line_ids)).reconcile()

Expand Down
6 changes: 3 additions & 3 deletions account_payment_group/views/account_payment_group_view.xml
Expand Up @@ -91,7 +91,7 @@

<group>
<group name="group1">
<field name="company_id" options="{'no_create': True, 'no_open': True}" groups="base.group_multi_company"/>
<field name="company_id" options="{'no_create': True, 'no_open': True}" />
<field name="currency_id" invisible="1"/>
<field name="partner_id" context="{'default_is_company': True}" string="Customer"
attrs="{'readonly':[('state', '!=', 'draft')],
Expand Down Expand Up @@ -130,7 +130,7 @@
<field
name="to_pay_move_line_ids"
context="{'tree_view_ref': 'account_payment_group.view_move_line_tree'}"
domain="[('partner_id.commercial_partner_id', '=', commercial_partner_id),('account_id.reconcile', '=', True),('reconciled', '=', False), ('full_reconcile_id', '=', False), ('company_id', '=', company_id), ('move_id.state', '=', 'posted'), ('account_id.internal_type', '=', 'receivable' if partner_type == 'customer' else 'payable')]"/>
domain="[('partner_id.commercial_partner_id', '=', commercial_partner_id),('account_id.reconcile', '=', True),('reconciled', '=', False), ('full_reconcile_id', '=', False), ('company_id', '=', company_id), ('move_id.state', '=', 'posted'), ('account_id.account_type', '=', 'asset_receivable' if partner_type == 'customer' else 'liability_payable')]"/>
</page>
<!-- no las pudimos hacer invisibles porque nos da error al venir de una factura y querer hacer las to pay lines tmb invisibles. lo bueno de hacerlas invisibles era que al confirmar se pasaba a las payment lines automaticamente -->
<page string="Payment Lines" attrs="{'invisible': [('payment_subtype', '=', 'double_validation'), ('state', '=', 'draft')]}">
Expand All @@ -148,7 +148,7 @@
<field
name="to_pay_move_line_ids"
context="{'tree_view_ref': 'account_payment_group.view_move_line_tree'}"
domain="[('partner_id.commercial_partner_id', '=', commercial_partner_id),('account_id.reconcile', '=', True),('reconciled', '=', False), ('full_reconcile_id', '=', False), ('company_id', '=', company_id), ('move_id.state', '=', 'posted'), ('account_id.internal_type', '=', 'receivable' if partner_type == 'customer' else 'payable')]" help="Payment will be automatically matched with the oldest lines of this list (by maturity date). You can remove any line you dont want to be matched."/>
domain="[('partner_id.commercial_partner_id', '=', commercial_partner_id),('account_id.reconcile', '=', True),('reconciled', '=', False), ('full_reconcile_id', '=', False), ('company_id', '=', company_id), ('move_id.state', '=', 'posted'), ('account_id.account_type', '=', 'asset_receivable' if partner_type == 'customer' else 'liability_payable')]" help="Payment will be automatically matched with the oldest lines of this list (by maturity date). You can remove any line you dont want to be matched."/>
</page>
<page string="Paid" states="posted">
<field name="matched_move_line_ids" context="{'payment_group_id': id, 'tree_view_ref': 'account_payment_group.view_move_line_with_matched_tree'}"/>
Expand Down
2 changes: 1 addition & 1 deletion account_payment_group_financial_surcharge/__manifest__.py
Expand Up @@ -20,6 +20,6 @@
],
'images': [
],
'installable': True,
'installable': False,
'auto_install': False,
}
2 changes: 1 addition & 1 deletion account_withholding/__manifest__.py
Expand Up @@ -31,7 +31,7 @@
'depends': [
'account',
],
'installable': True,
'installable': False,
'name': 'Withholdings on Payments',
'test': [],
'version': "15.0.1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion account_withholding_automatic/__manifest__.py
Expand Up @@ -36,7 +36,7 @@
'account_payment_group',
'account_withholding',
],
'installable': True,
'installable': False,
'name': 'Automatic Withholdings on Payments',
'test': [],
'version': "15.0.1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion card_installment/__manifest__.py
Expand Up @@ -11,7 +11,7 @@
'license': 'LGPL-3',
'images': [
],
'installable': True,
'installable': False,
'data': [
'security/ir.model.access.csv',
'security/ir_rule.xml',
Expand Down

0 comments on commit cf0b580

Please sign in to comment.