[FIX] snailmail, snailmail_account: do not make RPC call to compute the price

Since c2b55f3e0c, 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) <rar@odoo.com>
This commit is contained in:
Pierre Rousseau
2019-05-16 08:46:49 +00:00
parent e178ef9812
commit 05150281db
2 changed files with 1 additions and 65 deletions
@@ -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([
@@ -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):