diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index d6d7be96a27..dfa950d8ca9 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -475,7 +475,7 @@ class AccountInvoice(models.Model): account_id = pay_account.id payment_term_id = p.property_supplier_payment_term_id.id fiscal_position = p.property_account_position_id.id - 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: @@ -496,8 +496,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 e039f31353a..365095cfc5e 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 dde50d41683..3a15fe24de8 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -388,7 +388,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 2e4f132f27b..0658be752d7 100644 --- a/addons/account/views/account_view.xml +++ b/addons/account/views/account_view.xml @@ -1118,7 +1118,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/crm_partner_assign/crm_partner_assign.py b/addons/crm_partner_assign/crm_partner_assign.py index 433a3bdd5b9..48ca171dd58 100644 --- a/addons/crm_partner_assign/crm_partner_assign.py +++ b/addons/crm_partner_assign/crm_partner_assign.py @@ -14,7 +14,7 @@ class res_partner_grade(osv.osv): _columns = { 'sequence': fields.integer('Sequence'), 'active': fields.boolean('Active'), - 'name': fields.char('Level Name'), + 'name': fields.char('Level Name', translate=True), 'partner_weight': fields.integer('Level Weight', help="Gives the probability to assign a lead to this partner. (0 means no assignation.)"), } diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index 77a3c91ec7c..fd2794b9d35 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -197,6 +197,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 @@ -303,6 +304,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 bdfbb6d94bd..27966c44edd 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 -