From 7146a4b23b708d03eebf86f06885a33b0f33cbf4 Mon Sep 17 00:00:00 2001 From: wan Date: Thu, 28 Mar 2019 09:12:00 +0000 Subject: [PATCH] [IMP] account,pos: better distinction between customer payments Task 1934667 1. That's the partner type (and not the payment type) that should define if a payment is a customer or a supplier payment : a. When the partner type on the payment is "customer", the payment should be considered as a customer payment (and thus be visible from the menu customer payments) b. When the partner type on the payment is "supplier", the payment should be considered as a supplier payment (and thus be visible from the menu supplier payments) 2. The PoS should only create customer payments (you never pay suppliers through the PoS) The payment created should be with a partner type "Customer" But the partner field can stay empty if the customer wasn't set on the PoS Order 3. When I change the payment type while creating a payment from scratch, it shouldn't change the partner type Example : I'm creating a payment for a reimbursement, I'll create it from the customer payments menu (as I'm paying a customer), I'll tick the payment type "Send money" I don't expect the partner type to change to vendor. closes odoo/odoo#32381 Signed-off-by: Quentin De Paoli (qdp) --- addons/account/models/account_bank_statement.py | 2 ++ addons/account/models/account_payment.py | 6 +++--- addons/account/views/account_payment_view.xml | 4 ++-- addons/point_of_sale/models/pos_order.py | 10 +++++----- addons/point_of_sale/models/pos_session.py | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index 553b6080cc6..b63543a6b0f 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -517,6 +517,8 @@ class AccountBankStatementLine(models.Model): partner_type = 'supplier' else: partner_type = 'customer' + if not partner_type and self.env.context.get('default_partner_type'): + partner_type = self.env.context['default_partner_type'] currency = self.journal_id.currency_id or self.company_id.currency_id payment_methods = (total > 0) and self.journal_id.inbound_payment_method_ids or self.journal_id.outbound_payment_method_ids return { diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index dfc2b605790..72ea7718c08 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -496,14 +496,14 @@ class account_payment(models.Model): @api.onchange('payment_type') def _onchange_payment_type(self): - if not self.invoice_ids: + if not self.invoice_ids and not self.partner_type: # Set default partner type for the payment type if self.payment_type == 'inbound': self.partner_type = 'customer' elif self.payment_type == 'outbound': self.partner_type = 'supplier' - else: - self.partner_type = False + elif self.payment_type not in ('inbound', 'outbound'): + self.partner_type = False # Set payment method domain res = self._onchange_journal() if not res.get('domain', {}): diff --git a/addons/account/views/account_payment_view.xml b/addons/account/views/account_payment_view.xml index 5523f98d85a..40755b20e45 100644 --- a/addons/account/views/account_payment_view.xml +++ b/addons/account/views/account_payment_view.xml @@ -92,8 +92,8 @@ - - + + diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index 1c1a4bbe840..8303f2ec7ae 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -975,7 +975,7 @@ class PosOrder(models.Model): self.env['account.bank.statement.line'].with_context(context).create(args) self.amount_paid = sum(payment.amount for payment in self.statement_ids) return args.get('statement_id', False) - + def _prepare_refund_order_data(self, current_session=None): """ Prepare data for the creation of refund order based on the current order's data. Inheritance may inject its own data here @@ -999,7 +999,7 @@ class PosOrder(models.Model): 'amount_total': -self.amount_total, 'amount_paid': 0, } - + @api.multi def refund(self): """Create a copy of order for refund order""" @@ -1245,10 +1245,10 @@ class ReportSaleDetails(models.AbstractModel): SELECT aj.name, sum(amount) total FROM account_bank_statement_line AS absl, account_bank_statement AS abs, - account_journal AS aj + account_journal AS aj WHERE absl.statement_id = abs.id - AND abs.journal_id = aj.id - AND absl.id IN %s + AND abs.journal_id = aj.id + AND absl.id IN %s GROUP BY aj.name """, (tuple(st_line_ids),)) payments = self.env.cr.dictfetchall() diff --git a/addons/point_of_sale/models/pos_session.py b/addons/point_of_sale/models/pos_session.py index 502536c785f..d7a7f77c7fc 100644 --- a/addons/point_of_sale/models/pos_session.py +++ b/addons/point_of_sale/models/pos_session.py @@ -282,7 +282,7 @@ class PosSession(models.Model): # Close CashBox for session in self: company_id = session.config_id.company_id.id - ctx = dict(self.env.context, force_company=company_id, company_id=company_id) + ctx = dict(self.env.context, force_company=company_id, company_id=company_id, default_partner_type='customer') for st in session.statement_ids: if abs(st.difference) > st.journal_id.amount_authorized_diff: # The pos manager can close statements with maximums.