From 47aee73e0dd41f4b6ce20ce2c23940a95ee4b26b Mon Sep 17 00:00:00 2001 From: Graeme Gellatly Date: Wed, 29 May 2019 04:48:57 +1200 Subject: [PATCH] [IMP] Allow to attach from compose wizard By default we checked for an empty data dict in _get_report_values however the mail template sends a file type and editor key by default. We now check if the required company_id is in the dictionary. We also support supplying force_company in context for setting the company for auto generated emails. --- partner_statement/report/activity_statement.py | 4 +++- partner_statement/report/outstanding_statement.py | 4 +++- partner_statement/wizard/statement_common.py | 9 ++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/partner_statement/report/activity_statement.py b/partner_statement/report/activity_statement.py index 58242392..a86e3ac0 100644 --- a/partner_statement/report/activity_statement.py +++ b/partner_statement/report/activity_statement.py @@ -138,9 +138,11 @@ class ActivityStatement(models.AbstractModel): @api.multi def _get_report_values(self, docids, data): if not data: + data = {} + if 'company_id' not in data: wiz = self.env["activity.statement.wizard"].with_context( active_ids=docids, model="res.partner" ) - data = wiz.create({})._prepare_statement() + data.update(wiz.create({})._prepare_statement()) data['amount_field'] = 'amount' return super()._get_report_values(docids, data) diff --git a/partner_statement/report/outstanding_statement.py b/partner_statement/report/outstanding_statement.py index 28e8ae9a..74c6a07d 100644 --- a/partner_statement/report/outstanding_statement.py +++ b/partner_statement/report/outstanding_statement.py @@ -117,9 +117,11 @@ class OutstandingStatement(models.AbstractModel): @api.multi def _get_report_values(self, docids, data): if not data: + data = {} + if 'company_id' not in data: wiz = self.env["outstanding.statement.wizard"].with_context( active_ids=docids, model="res.partner" ) - data = wiz.create({})._prepare_statement() + data.update(wiz.create({})._prepare_statement()) data['amount_field'] = 'open_amount' return super()._get_report_values(docids, data) diff --git a/partner_statement/wizard/statement_common.py b/partner_statement/wizard/statement_common.py index e8476a8e..93885210 100644 --- a/partner_statement/wizard/statement_common.py +++ b/partner_statement/wizard/statement_common.py @@ -10,10 +10,17 @@ class StatementCommon(models.AbstractModel): _name = 'statement.common.wizard' _description = 'Statement Reports Common Wizard' + def _get_company(self): + return ( + self.env['res.company'].browse( + self.env.context.get('force_company')) or + self.env.user.company_id + ) + name = fields.Char() company_id = fields.Many2one( comodel_name='res.company', - default=lambda self: self.env.user.company_id, + default=_get_company, string='Company', required=True, )