Skip to content
Permalink
Browse files

[IMP] account: add account.reconcile.model.line

Task 2046908
Instead of having all the fields duplicated with second_*, we have now a
o2m allowing us to
* have more than 2 lines
* reduce duplicated code
* fix bugs and add features at only one place

We also remove the computation of writeoff and suggestions from the
client side as some code was 4-upled before (twice in in client and
twice in server side). The logic is now only at one place.
  • Loading branch information...
william-andre committed Aug 6, 2019
1 parent 596b372 commit 290f053eeb7bcc3bf0ef6959f24e5aa90ad8fdbd
@@ -504,7 +504,8 @@ def open_action_with_context(self):
[action] = self.env[model].browse(action_id).read()
action['context'] = ctx
if ctx.get('use_domain', False):
action['domain'] = ['|', ('journal_id', '=', self.id), ('journal_id', '=', False)]
journal_field = ctx.get('journal_field', 'journal_id')
action['domain'] = ['|', (journal_field, '=', self.id), (journal_field, '=', False)]
action['name'] += ' for journal ' + self.name
return action

Large diffs are not rendered by default.

@@ -669,44 +669,42 @@ def _prepare_reconcile_model_vals(self, company, account_reconcile_model, acc_te
""" This method generates a dictionary of all the values for the account.reconcile.model that will be created.
"""
self.ensure_one()
account_reconcile_model_lines = self.env['account.reconcile.model.line.template'].search([
('model_id', '=', account_reconcile_model.id)
])
return {
'name': account_reconcile_model.name,
'sequence': account_reconcile_model.sequence,
'has_second_line': account_reconcile_model.has_second_line,
'company_id': company.id,
'account_id': acc_template_ref[account_reconcile_model.account_id.id],
'label': account_reconcile_model.label,
'to_check': account_reconcile_model.to_check,
'amount_type': account_reconcile_model.amount_type,
'force_tax_included': account_reconcile_model.force_tax_included,
'amount': account_reconcile_model.amount,
'tax_ids': [[4, tax_template_ref[tax.id], 0] for tax in account_reconcile_model.tax_ids],
'second_account_id': account_reconcile_model.second_account_id and acc_template_ref[account_reconcile_model.second_account_id.id] or False,
'second_label': account_reconcile_model.second_label,
'second_amount_type': account_reconcile_model.second_amount_type,
'force_second_tax_included': account_reconcile_model.force_second_tax_included,
'second_amount': account_reconcile_model.second_amount,
'rule_type': account_reconcile_model.rule_type,
'auto_reconcile': account_reconcile_model.auto_reconcile,
'match_journal_ids': [(6, None, account_reconcile_model.match_journal_ids.ids)],
'match_nature': account_reconcile_model.match_nature,
'match_amount': account_reconcile_model.match_amount,
'match_amount_min': account_reconcile_model.match_amount_min,
'match_amount_max': account_reconcile_model.match_amount_max,
'match_label': account_reconcile_model.match_label,
'match_label_param': account_reconcile_model.match_label_param,
'match_note': account_reconcile_model.match_note,
'match_note_param': account_reconcile_model.match_note_param,
'match_transaction_type': account_reconcile_model.match_transaction_type,
'match_transaction_type_param': account_reconcile_model.match_transaction_type_param,
'match_same_currency': account_reconcile_model.match_same_currency,
'match_total_amount': account_reconcile_model.match_total_amount,
'match_total_amount_param': account_reconcile_model.match_total_amount_param,
'match_partner': account_reconcile_model.match_partner,
'match_partner_ids': [(6, None, account_reconcile_model.match_partner_ids.ids)],
'match_partner_category_ids': [(6, None, account_reconcile_model.match_partner_category_ids.ids)],
'second_tax_ids': [[4, tax_template_ref[tax.id], 0] for tax in account_reconcile_model.second_tax_ids],
}
'name': account_reconcile_model.name,
'sequence': account_reconcile_model.sequence,
'company_id': company.id,
'rule_type': account_reconcile_model.rule_type,
'auto_reconcile': account_reconcile_model.auto_reconcile,
'to_check': account_reconcile_model.to_check,
'match_journal_ids': [(6, None, account_reconcile_model.match_journal_ids.ids)],
'match_nature': account_reconcile_model.match_nature,
'match_amount': account_reconcile_model.match_amount,
'match_amount_min': account_reconcile_model.match_amount_min,
'match_amount_max': account_reconcile_model.match_amount_max,
'match_label': account_reconcile_model.match_label,
'match_label_param': account_reconcile_model.match_label_param,
'match_note': account_reconcile_model.match_note,
'match_note_param': account_reconcile_model.match_note_param,
'match_transaction_type': account_reconcile_model.match_transaction_type,
'match_transaction_type_param': account_reconcile_model.match_transaction_type_param,
'match_same_currency': account_reconcile_model.match_same_currency,
'match_total_amount': account_reconcile_model.match_total_amount,
'match_total_amount_param': account_reconcile_model.match_total_amount_param,
'match_partner': account_reconcile_model.match_partner,
'match_partner_ids': [(6, None, account_reconcile_model.match_partner_ids.ids)],
'match_partner_category_ids': [(6, None, account_reconcile_model.match_partner_category_ids.ids)],
'line_ids': [(0, 0, {
'account_id': acc_template_ref[line.account_id.id],
'label': line.label,
'amount_type': line.amount_type,
'force_tax_included': line.force_tax_included,
'amount': line.amount,
'tax_ids': [[4, tax_template_ref[tax.id], 0] for tax in line.tax_ids],
}) for line in account_reconcile_model_lines],
}

def generate_account_reconcile_model(self, tax_template_ref, acc_template_ref, company):
""" This method creates account reconcile models
@@ -1146,31 +1144,24 @@ class AccountReconcileModelTemplate(models.Model):
match_partner_category_ids = fields.Many2many('res.partner.category', string='Restrict Partner Categories to',
help='The reconciliation model will only be applied to the selected customer/vendor categories.')

# First part fields.
line_ids = fields.One2many('account.reconcile.model.line.template', 'model_id')


class AccountReconcileModelLineTemplate(models.Model):
_name = "account.reconcile.model.line.template"
_description = 'Reconcile Model Line Template'

model_id = fields.Many2one('account.reconcile.model.template')
sequence = fields.Integer(required=True, default=10)
account_id = fields.Many2one('account.account.template', string='Account', ondelete='cascade', domain=[('deprecated', '=', False)])
label = fields.Char(string='Journal Item Label')
amount_type = fields.Selection([
('fixed', 'Fixed'),
('percentage', 'Percentage of balance'),
('regex', 'From label'),
], required=True, default='percentage')
], required=True, default='percentage')
amount = fields.Float(string='Write-off Amount', digits=0, required=True, default=100.0, help="Fixed amount will count as a debit if it is negative, as a credit if it is positive.")
amount_from_label_regex = fields.Char(string="Amount from Label (regex)", default=r"([\d\.,]+)")
decimal_separator = fields.Char(help="Every character that is nor a digit nor this separator will be removed from the matching string")
force_tax_included = fields.Boolean(string='Tax Included in Price',
help='Force the tax to be managed as a price included tax.')
# Second part fields.
has_second_line = fields.Boolean(string='Add a second line', default=False)
force_tax_included = fields.Boolean(string='Tax Included in Price', help='Force the tax to be managed as a price included tax.')
tax_ids = fields.Many2many('account.tax.template', string='Taxes', ondelete='restrict')
second_account_id = fields.Many2one('account.account.template', string='Second Account', ondelete='cascade', domain=[('deprecated', '=', False)])
second_label = fields.Char(string='Second Journal Item Label')
second_amount_type = fields.Selection([
('fixed', 'Fixed'),
('percentage', 'Percentage of amount'),
('regex', 'From label'),
], string="Second Amount type",required=True, default='percentage')
second_amount = fields.Float(string='Second Write-off Amount', digits=0, required=True, default=100.0, help="Fixed amount will count as a debit if it is negative, as a credit if it is positive.")
second_amount_from_label_regex = fields.Char(string="Second Amount from Label (regex)", default=r"([\d\.,]+)")
force_second_tax_included = fields.Boolean(string='Second Tax Included in Price',
help='Force the second tax to be managed as a price included tax.')
second_tax_ids = fields.Many2many('account.tax.template', relation='account_reconcile_model_tmpl_account_tax_bis_rel', string='Second Taxes', ondelete='restrict')
@@ -173,6 +173,13 @@
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
</record>

<record model="ir.rule" id="account_reconcile_model_line_template_comp_rule">
<field name="name">Account reconcile model_line template company rule</field>
<field name="model_id" ref="model_account_reconcile_model_line"/>
<field name="global" eval="True"/>
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
</record>

<record model="ir.rule" id="account_payment_comp_rule">
<field name="name">Account payment company rule</field>
<field name="model_id" ref="model_account_payment"/>
@@ -64,6 +64,8 @@ access_account_account_tax_user,account.account.tag,model_account_account_tag,ac
access_account_reconcile_model_billing,account.reconcile.model.billing,model_account_reconcile_model,account.group_account_invoice,1,0,1,0
access_account_reconcile_model,account.reconcile.model,model_account_reconcile_model,account.group_account_user,1,1,1,1
access_account_reconcile_model_template,account.reconcile.model.template,model_account_reconcile_model_template,account.group_account_invoice,1,1,1,1
access_account_reconcile_model_line,account.reconcile.model.line,model_account_reconcile_model_line,account.group_account_user,1,1,1,1
access_account_reconcile_model_line_template,account.reconcile.model.line.template,model_account_reconcile_model_line_template,account.group_account_invoice,1,1,1,1
access_account_partial_reconcile_group_invoice,account.partial.reconcile.group.invoice,model_account_partial_reconcile,account.group_account_invoice,1,1,1,0
access_account_partial_reconcile,account.partial.reconcile,model_account_partial_reconcile,account.group_account_user,1,1,1,1
access_account_full_reconcile_group_invoice,account.full.reconcile.group.invoice,model_account_full_reconcile,account.group_account_invoice,1,1,1,0
@@ -45,15 +45,15 @@ def setUpClass(cls):
})

cls.rule_1 = cls.rule_0.copy()
cls.rule_1.account_id = current_assets_account
cls.rule_1.write({'line_ids': [(0, 0, {'account_id': current_assets_account.id})]})
cls.rule_1.match_partner = True
cls.rule_1.match_partner_ids |= cls.partner_1 + cls.partner_2
cls.rule_2 = cls.env['account.reconcile.model'].create({
'name': 'write-off model',
'rule_type': 'writeoff_suggestion',
'match_partner': True,
'match_partner_ids': [],
'account_id': current_assets_account.id,
'line_ids': [(0, 0, {'account_id': current_assets_account.id})],
})

invoice_number = cls.invoice_line_1.move_id.name
@@ -338,9 +338,11 @@ def test_auto_reconcile_with_tax(self):

self.rule_1.write({
'auto_reconcile': True,
'force_tax_included': True,
'tax_ids': [(6, 0, self.tax21.ids)],
'rule_type': 'writeoff_suggestion',
'line_ids': [(1, self.rule_1.line_ids.id, {
'force_tax_included': True,
'tax_ids': [(6, 0, self.tax21.ids)],
})]
})

self.bank_line_2.unlink()
@@ -61,4 +61,7 @@ def test_reconcile_model_fields(self):
'''Test fields consistency for ('account.reconcile.model', 'account.reconcile.model.template')
'''
self.check_fields_consistency('account.reconcile.model.template', 'account.reconcile.model', exceptions=['chart_template_id'])
self.check_fields_consistency('account.reconcile.model', 'account.reconcile.model.template', exceptions=['company_id', 'journal_id', 'analytic_account_id', 'second_journal_id', 'second_analytic_account_id', 'analytic_tag_ids', 'second_analytic_tag_ids'])
self.check_fields_consistency('account.reconcile.model', 'account.reconcile.model.template', exceptions=['company_id'])
# lines
self.check_fields_consistency('account.reconcile.model.line.template', 'account.reconcile.model.line', exceptions=['chart_template_id'])
self.check_fields_consistency('account.reconcile.model.line', 'account.reconcile.model.line.template', exceptions=['company_id', 'journal_id', 'analytic_account_id', 'analytic_tag_ids'])
@@ -103,7 +103,7 @@
<span role="separator">Reconciliation</span>
</div>
<div>
<a role="menuitem" type="object" name="open_action_with_context" context="{'action_name': 'action_account_reconcile_model', 'use_domain': True}" groups="account.group_account_manager">Reconciliation Models</a>
<a role="menuitem" type="object" name="open_action_with_context" context="{'action_name': 'action_account_reconcile_model', 'use_domain': True, 'journal_field': 'match_journal_ids'}" groups="account.group_account_manager">Reconciliation Models</a>
</div>
</div>
</div>

0 comments on commit 290f053

Please sign in to comment.
You can’t perform that action at this time.