From 05150281dbd051e5174f160b453192aed71d6a57 Mon Sep 17 00:00:00 2001 From: Pierre Rousseau Date: Thu, 16 May 2019 08:32:57 +0000 Subject: [PATCH] [FIX] snailmail, snailmail_account: do not make RPC call to compute the price MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since c2b55f3e0ccd621a77000dbe467176771404586f, a letter = 1 stamp, so we do not need to make RPC call anymore. closes odoo/odoo#33417 Signed-off-by: Rémi Rahir (rar) --- addons/snailmail/models/snailmail_letter.py | 64 ------------------- .../wizard/account_invoice_send.py | 2 +- 2 files changed, 1 insertion(+), 65 deletions(-) diff --git a/addons/snailmail/models/snailmail_letter.py b/addons/snailmail/models/snailmail_letter.py index bddadf07290..b058a6b9ecf 100644 --- a/addons/snailmail/models/snailmail_letter.py +++ b/addons/snailmail/models/snailmail_letter.py @@ -10,7 +10,6 @@ from odoo.exceptions import UserError from odoo.tools.safe_eval import safe_eval DEFAULT_ENDPOINT = 'https://iap-snailmail.odoo.com' -ESTIMATE_ENDPOINT = '/iap/snailmail/1/estimate' PRINT_ENDPOINT = '/iap/snailmail/1/print' ERROR_CODES = [ @@ -347,69 +346,6 @@ class SnailmailLetter(models.Model): self.write({'state': 'canceled', 'error_code': False}) self.send_snailmail_update() - @api.multi - def _snailmail_estimate(self): - """ - Send a request to estimate the cost of sending all the documents with - the differents options. - - The JSON object sent is the one generated from self._snailmail_create() - - arguments sent: - { - "documents":[{ - pages: int, - res_id: int (client_side, optional), - res_model: int (client_side, optional), - address: { - country_code: char (country name) - } - }], - 'color': # color on the letter, - 'duplex': # one/two side printing, - } - - The answer of the server is the same JSON object with some additionnal fields: - { - "total_cost": integer, //The cost of sending ALL the documents - body: JSON object (same as body param except new param 'cost' in each documents) - } - """ - endpoint = self.env['ir.config_parameter'].sudo().get_param('snailmail.endpoint', DEFAULT_ENDPOINT) - params = self._snailmail_create('estimate') - req = jsonrpc(endpoint + '/iap/snailmail/1/estimate', params=params) - - return req['total_cost'] - - @api.model - def _snailmail_estimate_from_documents(self, res_model, res_ids, partner_field=None): - endpoint = self.env['ir.config_parameter'].sudo().get_param('snailmail.endpoint', DEFAULT_ENDPOINT) - docs = self.env[res_model].browse(res_ids) - doc_list = [] - for doc in docs: - if partner_field: - country_code = doc[partner_field].country_id.code - else: - country_code = doc.country_id.code - val = { - 'pages': 1, - 'address': { - 'country_code': country_code, - }, - } - doc_list.append(val) - params = { - 'account_token': "", - 'documents': doc_list, - 'options': { - 'color': self.env.user.company_id.snailmail_color, - 'duplex': self.env.user.company_id.snailmail_duplex, - 'currency_name': 'EUR', - }, - } - req = jsonrpc(endpoint + '/iap/snailmail/1/estimate', params=params) - return req['total_cost'] - @api.model def _snailmail_cron(self): letters_send = self.search([ diff --git a/addons/snailmail_account/wizard/account_invoice_send.py b/addons/snailmail_account/wizard/account_invoice_send.py index e8575b645d8..25eba8778a4 100644 --- a/addons/snailmail_account/wizard/account_invoice_send.py +++ b/addons/snailmail_account/wizard/account_invoice_send.py @@ -35,7 +35,7 @@ class AccountInvoiceSend(models.TransientModel): @api.depends('snailmail_is_letter') def _compute_snailmail_cost(self): for wizard in self: - wizard.snailmail_cost = wizard.env['snailmail.letter']._snailmail_estimate_from_documents(wizard.invoice_ids._name, wizard.invoice_ids.ids, 'partner_id') + wizard.snailmail_cost = len(wizard.invoice_ids.ids) @api.multi def snailmail_print_action(self):