From 3fbfa32f73c003676172365b5505ceff792feef0 Mon Sep 17 00:00:00 2001 From: Andrea Date: Thu, 20 Dec 2018 16:39:00 +0100 Subject: [PATCH] Improvements as per feedback --- .../models/account_spread.py | 33 ++++++++++++++++++- .../models/account_spread_line.py | 5 ++- .../models/account_spread_template.py | 16 +++++++++ .../readme/ROADMAP.rst | 1 + .../views/account_spread_template.xml | 3 ++ ...account_spread_invoice_line_link_wizard.py | 1 + 6 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 account_spread_cost_revenue/readme/ROADMAP.rst diff --git a/account_spread_cost_revenue/models/account_spread.py b/account_spread_cost_revenue/models/account_spread.py index 29a52dc1..158143fa 100644 --- a/account_spread_cost_revenue/models/account_spread.py +++ b/account_spread_cost_revenue/models/account_spread.py @@ -188,6 +188,12 @@ class AccountSpread(models.Model): else: if self.invoice_type in ['out_invoice', 'out_refund']: self.invoice_type = 'in_invoice' + if self.template_id.period_number: + self.period_number = self.template_id.period_number + if self.template_id.period_type: + self.period_type = self.template_id.period_type + if self.template_id.start_date: + self.spread_date = self.template_id.start_date @api.onchange('invoice_type', 'company_id') def onchange_invoice_type(self): @@ -326,7 +332,11 @@ class AccountSpread(models.Model): spread_date = self._next_line_date(month_day, spread_date) self.write({'line_ids': commands}) - self.message_post(body=_("Spread table created.")) + invoice_type_selection = dict(self.fields_get( + allfields=['invoice_type'] + )['invoice_type']['selection'])[self.invoice_type] + msg_body = _("Spread table '%s' created.") % invoice_type_selection + self.message_post(body=msg_body) @api.multi def _get_number_of_periods(self, month_day): @@ -398,8 +408,29 @@ class AccountSpread(models.Model): for spread in self: spread_mls = spread.line_ids.mapped('move_id.line_ids') spread_mls.remove_move_reconcile() + inv_link = '%s' % ( + spread.invoice_id.id, _("Invoice")) + msg_body = _("Unlinked invoice line '%s' (view %s).") % ( + spread.invoice_line_id.name, inv_link) + spread.message_post(body=msg_body) spread.write({'invoice_line_ids': [(5, 0, 0)]}) + @api.multi + def unlink(self): + for spread in self: + if spread.invoice_line_id: + raise UserError( + _('Cannot delete spread(s) that are linked ' + 'to an invoice line.')) + posted_line_ids = self.line_ids.filtered( + lambda x: x.move_id.state == 'posted') + if posted_line_ids: + raise ValidationError( + _('Cannot delete spread(s): there are some ' + 'posted Journal Entries.')) + return super().unlink() + @api.multi def reconcile_spread_moves(self): for spread in self: diff --git a/account_spread_cost_revenue/models/account_spread_line.py b/account_spread_cost_revenue/models/account_spread_line.py index 34627b2f..8be52f6b 100644 --- a/account_spread_cost_revenue/models/account_spread_line.py +++ b/account_spread_cost_revenue/models/account_spread_line.py @@ -34,7 +34,10 @@ class AccountInvoiceSpreadLine(models.Model): if created_moves: post_msg = _("Created move(s) ") - post_msg += ", ".join(str(id) for id in created_moves.ids) + post_msg += ", ".join( + '%s' % (move.id, move.name) + for move in created_moves) spread.message_post(body=post_msg) spread._reconcile_spread_moves(created_moves) diff --git a/account_spread_cost_revenue/models/account_spread_template.py b/account_spread_cost_revenue/models/account_spread_template.py index 530e6367..3bfa656c 100644 --- a/account_spread_cost_revenue/models/account_spread_template.py +++ b/account_spread_cost_revenue/models/account_spread_template.py @@ -27,6 +27,15 @@ class AccountSpreadTemplate(models.Model): 'account.account', string='Spread Balance Sheet Account', required=True) + period_number = fields.Integer( + string='Number of Repetitions', + help="Define the number of spread lines") + period_type = fields.Selection([ + ('month', 'Month'), + ('quarter', 'Quarter'), + ('year', 'Year')], + help="Period length for the entries") + start_date = fields.Date() @api.model def default_get(self, fields): @@ -74,5 +83,12 @@ class AccountSpreadTemplate(models.Model): invoice_type = 'in_invoice' spread_vals['credit_account_id'] = self.spread_account_id.id + if self.period_number: + spread_vals['period_number'] = self.period_number + if self.period_type: + spread_vals['period_type'] = self.period_type + if self.start_date: + spread_vals['spread_date'] = self.start_date + spread_vals['invoice_type'] = invoice_type return spread_vals diff --git a/account_spread_cost_revenue/readme/ROADMAP.rst b/account_spread_cost_revenue/readme/ROADMAP.rst new file mode 100644 index 00000000..be52964a --- /dev/null +++ b/account_spread_cost_revenue/readme/ROADMAP.rst @@ -0,0 +1 @@ +* Add option to post all spread lines in one click diff --git a/account_spread_cost_revenue/views/account_spread_template.xml b/account_spread_cost_revenue/views/account_spread_template.xml index b51a9d1e..8be8e771 100644 --- a/account_spread_cost_revenue/views/account_spread_template.xml +++ b/account_spread_cost_revenue/views/account_spread_template.xml @@ -16,6 +16,9 @@ + + + diff --git a/account_spread_cost_revenue/wizards/account_spread_invoice_line_link_wizard.py b/account_spread_cost_revenue/wizards/account_spread_invoice_line_link_wizard.py index 5435c7ec..3b5c0c78 100644 --- a/account_spread_cost_revenue/wizards/account_spread_invoice_line_link_wizard.py +++ b/account_spread_cost_revenue/wizards/account_spread_invoice_line_link_wizard.py @@ -147,6 +147,7 @@ class AccountSpreadInvoiceLineLinkWizard(models.TransientModel): spread_vals = self.template_id._prepare_spread_from_template() date_invoice = self.invoice_id.date_invoice + date_invoice = date_invoice or self.template_id.start_date date_invoice = date_invoice or fields.Date.today() spread_vals['spread_date'] = date_invoice