diff --git a/account_move_template/models/account_move_template.py b/account_move_template/models/account_move_template.py index 0d548249..6faaee54 100644 --- a/account_move_template/models/account_move_template.py +++ b/account_move_template/models/account_move_template.py @@ -117,6 +117,9 @@ class AccountMoveTemplateLine(models.Model): python_code = fields.Text('Python Code') move_line_type = fields.Selection( [('cr', 'Credit'), ('dr', 'Debit')], required=True, string='Direction') + payment_term_id = fields.Many2one( + 'account.payment.term', string='Payment Terms', + help="Used to compute the due date of the journal item.") _sql_constraints = [( 'sequence_template_uniq', diff --git a/account_move_template/readme/USAGE.rst b/account_move_template/readme/USAGE.rst index 568a47a7..8e4c574d 100644 --- a/account_move_template/readme/USAGE.rst +++ b/account_move_template/readme/USAGE.rst @@ -1,13 +1,13 @@ To create new templates: -#. Make sure that you have flagged *Show Full Accounting Features* in your +#. Make sure that you have flagged *Show Full Accounting Features* on your user, and that the user belongs to the *Billing Manager* group. -#. Go to *Invoicing / Configuration / Accounting / Journal Templates* and - define there your template. You can choose to complete a line using a - defined formula, based on other lines, or by requiring the user input. +#. Go to *Invoicing / Configuration / Accounting / Journal Entry Templates* and + define there your templates. You can choose to complete a line using a + defined formula, based on other lines, or by requiring user input. To use an existing template: -#. Go to *Invoicing / Adviser / Accounting Entries / Create Journal Entry from Template* -#. Select one of the available templates and optionally a partner. -#. Complete the entries according to the template and press *Load* +#. Go to *Invoicing / Accounting / Accounting Entries / Create Journal Entry from Template* +#. Select one of the available templates. +#. Complete the entries according to the template and click on the button *Generate Journal Entry*. diff --git a/account_move_template/view/account_move_template.xml b/account_move_template/view/account_move_template.xml index 03b2530d..cf0f7bce 100644 --- a/account_move_template/view/account_move_template.xml +++ b/account_move_template/view/account_move_template.xml @@ -16,6 +16,7 @@ + @@ -28,24 +29,25 @@
- - + + + - + - + - + diff --git a/account_move_template/wizard/account_move_template_run.py b/account_move_template/wizard/account_move_template_run.py index 2e290e15..c8ee0d99 100644 --- a/account_move_template/wizard/account_move_template_run.py +++ b/account_move_template/wizard/account_move_template_run.py @@ -28,20 +28,21 @@ class AccountMoveTemplateRun(models.TransientModel): ('set_lines', 'Set Lines'), ], readonly=True, default='select_template') - def _prepare_wizard_line(self, line): + def _prepare_wizard_line(self, tmpl_line): vals = { 'wizard_id': self.id, - 'sequence': line.sequence, - 'name': line.name, + 'sequence': tmpl_line.sequence, + 'name': tmpl_line.name, 'amount': 0.0, - 'account_id': line.account_id.id, - 'partner_id': line.partner_id.id or False, - 'move_line_type': line.move_line_type, - 'tax_ids': [(6, 0, line.tax_ids.ids)], - 'tax_line_id': line.tax_line_id.id, - 'analytic_account_id': line.analytic_account_id.id, - 'analytic_tag_ids': [(6, 0, line.analytic_tag_ids.ids)], - 'note': line.note, + 'account_id': tmpl_line.account_id.id, + 'partner_id': tmpl_line.partner_id.id or False, + 'move_line_type': tmpl_line.move_line_type, + 'tax_ids': [(6, 0, tmpl_line.tax_ids.ids)], + 'tax_line_id': tmpl_line.tax_line_id.id, + 'analytic_account_id': tmpl_line.analytic_account_id.id, + 'analytic_tag_ids': [(6, 0, tmpl_line.analytic_tag_ids.ids)], + 'note': tmpl_line.note, + 'payment_term_id': tmpl_line.payment_term_id.id or False, } return vals @@ -56,9 +57,9 @@ class AccountMoveTemplateRun(models.TransientModel): self.template_id.name, self.template_id.company_id.display_name, self.company_id.display_name)) - lines = self.template_id.line_ids - for line in lines.filtered(lambda l: l.type == 'input'): - vals = self._prepare_wizard_line(line) + tmpl_lines = self.template_id.line_ids + for tmpl_line in tmpl_lines.filtered(lambda l: l.type == 'input'): + vals = self._prepare_wizard_line(tmpl_line) amtlro.create(vals) self.write({ 'journal_id': self.template_id.journal_id.id, @@ -117,6 +118,11 @@ class AccountMoveTemplateRun(models.TransientModel): return move_vals def _prepare_move_line(self, line, amount): + date_maturity = False + if line.payment_term_id: + pterm_list = line.payment_term_id.compute( + value=1, date_ref=self.date)[0] + date_maturity = max(l[0] for l in pterm_list) debit = line.move_line_type == 'dr' values = { 'name': line.name, @@ -126,6 +132,7 @@ class AccountMoveTemplateRun(models.TransientModel): 'debit': debit and amount or 0.0, 'partner_id': self.partner_id.id or line.partner_id.id, 'tax_line_id': line.tax_line_id.id, + 'date_maturity': date_maturity or self.date, } if line.analytic_tag_ids: values['analytic_tag_ids'] = [(6, 0, line.analytic_tag_ids.ids)] @@ -158,6 +165,8 @@ class AccountMoveTemplateLineRun(models.TransientModel): ondelete='restrict', readonly=True) partner_id = fields.Many2one( 'res.partner', readonly=True, string='Partner') + payment_term_id = fields.Many2one( + 'account.payment.term', string='Payment Terms') move_line_type = fields.Selection( [('cr', 'Credit'), ('dr', 'Debit')], required=True, readonly=True, string='Direction') diff --git a/account_move_template/wizard/account_move_template_run_view.xml b/account_move_template/wizard/account_move_template_run_view.xml index cde4f76e..7e41db32 100644 --- a/account_move_template/wizard/account_move_template_run_view.xml +++ b/account_move_template/wizard/account_move_template_run_view.xml @@ -29,6 +29,7 @@ +