diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index c6f8d809ec8..531b12fac5f 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -486,7 +486,6 @@ class AccountInvoice(models.Model): addr = self.partner_id.address_get(['delivery']) fiscal_position = self.env['account.fiscal.position'].get_fiscal_position(self.partner_id.id, delivery_id=addr['delivery']) - bank_id = p.bank_ids and p.bank_ids.ids[0] or False # If partner has no warning, check its company if p.invoice_warn == 'no-message' and p.parent_id: @@ -507,8 +506,12 @@ class AccountInvoice(models.Model): self.payment_term_id = payment_term_id self.fiscal_position_id = fiscal_position - if type in ('in_invoice', 'in_refund'): + if type in ('in_invoice', 'out_refund'): + bank_ids = p.commercial_partner_id.bank_ids + bank_id = bank_ids[0].id if bank_ids else False self.partner_bank_id = bank_id + return {'domain': {'partner_bank_id': [('id', 'in', bank_ids.ids)]}} + return {} @api.onchange('journal_id') diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 807ae8ff5d5..bf5234366a2 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -695,22 +695,37 @@ class AccountMoveLine(models.Model): line_currency = (line.currency_id and line.amount_currency) and line.currency_id or company_currency amount_currency_str = "" total_amount_currency_str = "" - if line_currency != company_currency and target_currency != company_currency: + if line_currency != company_currency and target_currency == line_currency: + # The payment currency is the invoice currency, but they are different than the company currency + # We use the `amount_currency` computed during the invoice validation, at the invoice date + # to avoid exchange gain/loss + # e.g. an invoice of 100€ must be paid with 100€, whatever the company currency and the exchange rates total_amount = line.amount_currency actual_debit = debit > 0 and amount_currency or 0.0 actual_credit = credit > 0 and -amount_currency or 0.0 + currency = line_currency else: + # Either: + # - the invoice, payment, company currencies are all the same, + # - the payment currency is the company currency, but the invoice currency is different, + # - the invoice currency is the company currency, but the payment currency is different, + # - the invoice, payment and company currencies are all different. + # For the two first cases, we can simply use the debit/credit of the invoice move line, which are always in the company currency, + # and this is what the target need. + # For the two last cases, we can use the debit/credit which are in the company currency, and then change them to the target currency total_amount = abs(debit - credit) actual_debit = debit > 0 and amount or 0.0 actual_credit = credit > 0 and -amount or 0.0 - if line_currency != target_currency and target_currency != company_currency: + currency = company_currency + if line_currency != target_currency: amount_currency_str = formatLang(self.env, abs(actual_debit or actual_credit), currency_obj=line_currency) total_amount_currency_str = formatLang(self.env, total_amount, currency_obj=line_currency) + if currency != target_currency: ctx = context.copy() ctx.update({'date': target_date or line.date}) - total_amount = line_currency.with_context(ctx).compute(total_amount, target_currency) - actual_debit = line_currency.with_context(ctx).compute(actual_debit, target_currency) - actual_credit = line_currency.with_context(ctx).compute(actual_credit, target_currency) + total_amount = currency.with_context(ctx).compute(total_amount, target_currency) + actual_debit = currency.with_context(ctx).compute(actual_debit, target_currency) + actual_credit = currency.with_context(ctx).compute(actual_credit, target_currency) amount_str = formatLang(self.env, abs(actual_debit or actual_credit), currency_obj=target_currency) total_amount_str = formatLang(self.env, total_amount, currency_obj=target_currency) diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index c052440f1fb..3ac4cbdec0a 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -396,7 +396,7 @@ class account_payment(models.Model): # the writeoff debit and credit must be computed from the invoice residual in company currency # minus the payment amount in company currency, and not from the payment difference in the payment currency # to avoid loss of precision during the currency rate computations. See revision 20935462a0cabeb45480ce70114ff2f4e91eaf79 for a detailed example. - total_residual_company_signed = self._compute_total_invoices_amount() + total_residual_company_signed = sum(invoice.residual_company_signed for invoice in self.invoice_ids) total_payment_company_signed = self.currency_id.with_context(date=self.payment_date).compute(self.amount, self.company_id.currency_id) if self.invoice_ids[0].type in ['in_invoice', 'out_refund']: amount_wo = total_payment_company_signed - total_residual_company_signed diff --git a/addons/account/views/account_view.xml b/addons/account/views/account_view.xml index c742222efea..64472a37f50 100644 --- a/addons/account/views/account_view.xml +++ b/addons/account/views/account_view.xml @@ -1121,7 +1121,6 @@ - diff --git a/addons/crm/data/sales_config_settings_data.xml b/addons/crm/data/sales_config_settings_data.xml index 61bda872c46..331fe0514dc 100644 --- a/addons/crm/data/sales_config_settings_data.xml +++ b/addons/crm/data/sales_config_settings_data.xml @@ -1,8 +1,8 @@ - + - + diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index ae0477e1fb2..519f6c84908 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -198,6 +198,7 @@ class PosOrder(models.Model): grouped_data = {} have_to_group_by = session and session.config_id.group_by or False + rounding_method = session and session.config_id.company_id.tax_calculation_rounding_method for order in self.filtered(lambda o: not o.account_move or order.state == 'paid'): current_company = order.sale_journal.company_id @@ -296,6 +297,14 @@ class PosOrder(models.Model): 'partner_id': partner_id }) + # round tax lines per order + if rounding_method == 'round_globally': + for group_key, group_value in grouped_data.iteritems(): + if group_key[0] == 'tax': + for line in group_value: + line['credit'] = cur.round(line['credit']) + line['debit'] = cur.round(line['debit']) + # counterpart insert_data('counter_part', { 'name': _("Trade Receivables"), # order.name, diff --git a/addons/point_of_sale/static/src/xml/pos.xml b/addons/point_of_sale/static/src/xml/pos.xml index 01da370ed18..3821fd212dc 100644 --- a/addons/point_of_sale/static/src/xml/pos.xml +++ b/addons/point_of_sale/static/src/xml/pos.xml @@ -336,7 +336,7 @@
Country -