[FIX] sale: down payment translation

- Set a customer language to a different language, e.g. French
- Create a SO, add a product and validate
- Create a down payment

The down payment invoice is partially translated in French.

This was first solved in fc659d3f78 but broken in
0e73eca1364c8e0df93cd.

opw-2365982

closes odoo/odoo#61207

X-original-commit: f10b98d1776659f291b2f7f8a4a2111e4f106667
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
Nicolas Martinelli
2020-11-02 17:10:14 +00:00
parent a021d627f1
commit 39ab53a4d6
@@ -104,12 +104,14 @@ class SaleAdvancePaymentInv(models.TransientModel):
return invoice_vals
def _get_advance_details(self, order):
context = {'lang': order.partner_id.lang}
if self.advance_payment_method == 'percentage':
amount = order.amount_untaxed * self.amount / 100
name = _("Down payment of %s%%") % (self.amount)
else:
amount = self.fixed_amount
name = _('Down Payment')
del context
return amount, name
@@ -130,6 +132,7 @@ class SaleAdvancePaymentInv(models.TransientModel):
return invoice
def _prepare_so_line(self, order, analytic_tag_ids, tax_ids, amount):
context = {'lang': order.partner_id.lang}
so_values = {
'name': _('Down Payment: %s') % (time.strftime('%m %Y'),),
'price_unit': amount,
@@ -143,6 +146,7 @@ class SaleAdvancePaymentInv(models.TransientModel):
'is_downpayment': True,
'sequence': order.order_line and order.order_line[-1].sequence + 1 or 10,
}
del context
return so_values
def create_invoices(self):
@@ -167,14 +171,12 @@ class SaleAdvancePaymentInv(models.TransientModel):
raise UserError(_("The product used to invoice a down payment should be of type 'Service'. Please use another product or update this product."))
taxes = self.product_id.taxes_id.filtered(lambda r: not order.company_id or r.company_id == order.company_id)
tax_ids = order.fiscal_position_id.map_tax(taxes, self.product_id, order.partner_shipping_id).ids
context = {'lang': order.partner_id.lang}
analytic_tag_ids = []
for line in order.order_line:
analytic_tag_ids = [(4, analytic_tag.id, None) for analytic_tag in line.analytic_tag_ids]
so_line_values = self._prepare_so_line(order, analytic_tag_ids, tax_ids, amount)
so_line = sale_line_obj.create(so_line_values)
del context
self._create_invoice(order, so_line, amount)
if self._context.get('open_invoices', False):
return sale_orders.action_view_invoice()