2
0

account_move_template: Add support for date_maturity

Update README
Add a name on all groups in views
This commit is contained in:
Alexis de Lattre 2019-04-16 11:15:58 +02:00 committed by Abraham Anes
parent d2da4f4276
commit 1d5b817a1e
5 changed files with 41 additions and 26 deletions

View File

@ -117,6 +117,9 @@ class AccountMoveTemplateLine(models.Model):
python_code = fields.Text('Python Code') python_code = fields.Text('Python Code')
move_line_type = fields.Selection( move_line_type = fields.Selection(
[('cr', 'Credit'), ('dr', 'Debit')], required=True, string='Direction') [('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 = [( _sql_constraints = [(
'sequence_template_uniq', 'sequence_template_uniq',

View File

@ -1,13 +1,13 @@
To create new templates: 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. user, and that the user belongs to the *Billing Manager* group.
#. Go to *Invoicing / Configuration / Accounting / Journal Templates* and #. Go to *Invoicing / Configuration / Accounting / Journal Entry Templates* and
define there your template. You can choose to complete a line using a define there your templates. You can choose to complete a line using a
defined formula, based on other lines, or by requiring the user input. defined formula, based on other lines, or by requiring user input.
To use an existing template: To use an existing template:
#. Go to *Invoicing / Adviser / Accounting Entries / Create Journal Entry from Template* #. Go to *Invoicing / Accounting / Accounting Entries / Create Journal Entry from Template*
#. Select one of the available templates and optionally a partner. #. Select one of the available templates.
#. Complete the entries according to the template and press *Load* #. Complete the entries according to the template and click on the button *Generate Journal Entry*.

View File

@ -16,6 +16,7 @@
<field name="note"/> <field name="note"/>
<field name="tax_line_id" invisible="1"/> <field name="tax_line_id" invisible="1"/>
<field name="tax_ids" widget="many2many_tags" options="{'no_create': True}"/> <field name="tax_ids" widget="many2many_tags" options="{'no_create': True}"/>
<field name="payment_term_id"/>
<field name="company_id" invisible="1"/> <field name="company_id" invisible="1"/>
<field name="company_currency_id" invisible="1"/> <field name="company_currency_id" invisible="1"/>
</tree> </tree>
@ -28,24 +29,25 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="Journal Entry Template Line"> <form string="Journal Entry Template Line">
<sheet> <sheet>
<group> <group name="main">
<group> <group name="account">
<field name="sequence"/> <field name="sequence"/>
<field name="name"/> <field name="name"/>
<field name="account_id" domain="[('company_id', '=', company_id)]"/> <field name="account_id" domain="[('company_id', '=', company_id)]"/>
<field name="partner_id"/> <field name="partner_id"/>
<field name="payment_term_id"/>
<field name="company_id" invisible="1"/> <field name="company_id" invisible="1"/>
</group> </group>
<group groups="analytic.group_analytic_accounting" string="Analytic"> <group groups="analytic.group_analytic_accounting" string="Analytic" name="analytic">
<field name="analytic_account_id" domain="[('company_id','=',company_id)]"/> <field name="analytic_account_id" domain="[('company_id','=',company_id)]"/>
<field name="analytic_tag_ids" widget="many2many_tags"/> <field name="analytic_tag_ids" widget="many2many_tags"/>
</group> </group>
<group> <group name="amount" string="Amount">
<field name="move_line_type"/> <field name="move_line_type"/>
<field name="type"/> <field name="type"/>
<field name="note"/> <field name="note"/>
</group> </group>
<group string="Taxes"> <group string="Taxes" name="tax">
<field name="tax_line_id"/> <field name="tax_line_id"/>
<field name="tax_ids" widget="many2many_tags"/> <field name="tax_ids" widget="many2many_tags"/>
</group> </group>

View File

@ -28,20 +28,21 @@ class AccountMoveTemplateRun(models.TransientModel):
('set_lines', 'Set Lines'), ('set_lines', 'Set Lines'),
], readonly=True, default='select_template') ], readonly=True, default='select_template')
def _prepare_wizard_line(self, line): def _prepare_wizard_line(self, tmpl_line):
vals = { vals = {
'wizard_id': self.id, 'wizard_id': self.id,
'sequence': line.sequence, 'sequence': tmpl_line.sequence,
'name': line.name, 'name': tmpl_line.name,
'amount': 0.0, 'amount': 0.0,
'account_id': line.account_id.id, 'account_id': tmpl_line.account_id.id,
'partner_id': line.partner_id.id or False, 'partner_id': tmpl_line.partner_id.id or False,
'move_line_type': line.move_line_type, 'move_line_type': tmpl_line.move_line_type,
'tax_ids': [(6, 0, line.tax_ids.ids)], 'tax_ids': [(6, 0, tmpl_line.tax_ids.ids)],
'tax_line_id': line.tax_line_id.id, 'tax_line_id': tmpl_line.tax_line_id.id,
'analytic_account_id': line.analytic_account_id.id, 'analytic_account_id': tmpl_line.analytic_account_id.id,
'analytic_tag_ids': [(6, 0, line.analytic_tag_ids.ids)], 'analytic_tag_ids': [(6, 0, tmpl_line.analytic_tag_ids.ids)],
'note': line.note, 'note': tmpl_line.note,
'payment_term_id': tmpl_line.payment_term_id.id or False,
} }
return vals return vals
@ -56,9 +57,9 @@ class AccountMoveTemplateRun(models.TransientModel):
self.template_id.name, self.template_id.name,
self.template_id.company_id.display_name, self.template_id.company_id.display_name,
self.company_id.display_name)) self.company_id.display_name))
lines = self.template_id.line_ids tmpl_lines = self.template_id.line_ids
for line in lines.filtered(lambda l: l.type == 'input'): for tmpl_line in tmpl_lines.filtered(lambda l: l.type == 'input'):
vals = self._prepare_wizard_line(line) vals = self._prepare_wizard_line(tmpl_line)
amtlro.create(vals) amtlro.create(vals)
self.write({ self.write({
'journal_id': self.template_id.journal_id.id, 'journal_id': self.template_id.journal_id.id,
@ -117,6 +118,11 @@ class AccountMoveTemplateRun(models.TransientModel):
return move_vals return move_vals
def _prepare_move_line(self, line, amount): 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' debit = line.move_line_type == 'dr'
values = { values = {
'name': line.name, 'name': line.name,
@ -126,6 +132,7 @@ class AccountMoveTemplateRun(models.TransientModel):
'debit': debit and amount or 0.0, 'debit': debit and amount or 0.0,
'partner_id': self.partner_id.id or line.partner_id.id, 'partner_id': self.partner_id.id or line.partner_id.id,
'tax_line_id': line.tax_line_id.id, 'tax_line_id': line.tax_line_id.id,
'date_maturity': date_maturity or self.date,
} }
if line.analytic_tag_ids: if line.analytic_tag_ids:
values['analytic_tag_ids'] = [(6, 0, line.analytic_tag_ids.ids)] values['analytic_tag_ids'] = [(6, 0, line.analytic_tag_ids.ids)]
@ -158,6 +165,8 @@ class AccountMoveTemplateLineRun(models.TransientModel):
ondelete='restrict', readonly=True) ondelete='restrict', readonly=True)
partner_id = fields.Many2one( partner_id = fields.Many2one(
'res.partner', readonly=True, string='Partner') 'res.partner', readonly=True, string='Partner')
payment_term_id = fields.Many2one(
'account.payment.term', string='Payment Terms')
move_line_type = fields.Selection( move_line_type = fields.Selection(
[('cr', 'Credit'), ('dr', 'Debit')], [('cr', 'Credit'), ('dr', 'Debit')],
required=True, readonly=True, string='Direction') required=True, readonly=True, string='Direction')

View File

@ -29,6 +29,7 @@
<field name="move_line_type" /> <field name="move_line_type" />
<field name="amount" /> <field name="amount" />
<field name="note"/> <field name="note"/>
<field name="payment_term_id"/>
<field name="company_id" invisible="1"/> <field name="company_id" invisible="1"/>
<field name="company_currency_id" invisible="1"/> <field name="company_currency_id" invisible="1"/>
</tree> </tree>