From d5e2708f8e925b1aa8a2e2667cc5207f8181de87 Mon Sep 17 00:00:00 2001 From: wan Date: Thu, 28 Mar 2019 11:19:05 +0000 Subject: [PATCH] [IMP] account: generic usability improvements Task 1950665 1. Define a tax on an account should tell if it's a SALE or PURCHASE tax 2. Credit Note creation from an invoice, label improvement 3. Improve Payable/Receivable account detection from bank statement reconciliation closes odoo/odoo#32775 Signed-off-by: Quentin De Paoli (qdp) --- addons/account/models/account.py | 4 ++-- addons/account/models/reconciliation_widget.py | 6 ++++-- .../src/js/reconciliation/reconciliation_model.js | 10 ++++++++-- addons/account/wizard/account_invoice_refund.py | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/addons/account/models/account.py b/addons/account/models/account.py index 2805c22e862..ba2615f946b 100644 --- a/addons/account/models/account.py +++ b/addons/account/models/account.py @@ -88,7 +88,7 @@ class AccountAccount(models.Model): reconcile = fields.Boolean(string='Allow Reconciliation', default=False, help="Check this box if this account allows invoices & payments matching of journal items.") tax_ids = fields.Many2many('account.tax', 'account_account_tax_default_rel', - 'account_id', 'tax_id', string='Default Taxes') + 'account_id', 'tax_id', string='Default Taxes', context={'append_type_to_tax_name': True}) note = fields.Text('Internal Notes') company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env['res.company']._company_default_get('account.account')) @@ -962,7 +962,7 @@ class AccountTax(models.Model): def name_get(self): if not self._context.get('append_type_to_tax_name'): return super(AccountTax, self).name_get() - return [(tax.id, '%s (%s)' % (tax.name, tax.type_tax_use)) for tax in self] + return [(tax.id, '%s (%s)' % (tax.name, dict(self._fields['type_tax_use']._description_selection(self.env))[tax.type_tax_use])) for tax in self] @api.model def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): diff --git a/addons/account/models/reconciliation_widget.py b/addons/account/models/reconciliation_widget.py index 4683afab86f..db3fb9437a1 100644 --- a/addons/account/models/reconciliation_widget.py +++ b/addons/account/models/reconciliation_widget.py @@ -689,10 +689,12 @@ class AccountReconciliation(models.AbstractModel): 'company_id': st_line.company_id.id, } if st_line.partner_id: - if amount > 0: + if st_line.partner_id.supplier and not st_line.partner_id.customer: + data['open_balance_account_id'] = st_line.partner_id.property_account_payable_id.id + elif not st_line.partner_id.supplier and st_line.partner_id.customer: data['open_balance_account_id'] = st_line.partner_id.property_account_receivable_id.id else: - data['open_balance_account_id'] = st_line.partner_id.property_account_payable_id.id + data['open_balance_account_id'] = amount > 0 and st_line.partner_id.property_account_receivable_id.id or st_line.partner_id.property_account_payable_id.id return data diff --git a/addons/account/static/src/js/reconciliation/reconciliation_model.js b/addons/account/static/src/js/reconciliation/reconciliation_model.js index 601f4cec773..c28790796d2 100644 --- a/addons/account/static/src/js/reconciliation/reconciliation_model.js +++ b/addons/account/static/src/js/reconciliation/reconciliation_model.js @@ -837,11 +837,17 @@ var StatementModel = BasicModel.extend({ return this._rpc({ model: 'res.partner', method: 'read', - args: [partner_id, ["property_account_receivable_id", "property_account_payable_id"]], + args: [partner_id, ["property_account_receivable_id", "property_account_payable_id", "customer", "supplier"]], }).then(function (result) { if (result.length > 0) { var line = self.getLine(handle); - self.lines[handle].st_line.open_balance_account_id = line.balance.amount < 0 ? result[0]['property_account_payable_id'][0] : result[0]['property_account_receivable_id'][0]; + if (result[0]['supplier'] && !result[0]['customer']) { + self.lines[handle].st_line.open_balance_account_id = result[0]['property_account_payable_id'][0]; + } else if (!result[0]['supplier'] && result[0]['customer']) { + self.lines[handle].st_line.open_balance_account_id = result[0]['property_account_receivable_id'][0]; + } else { + self.lines[handle].st_line.open_balance_account_id = line.balance.amount < 0 ? result[0]['property_account_payable_id'][0] : result[0]['property_account_receivable_id'][0]; + } } }); }, diff --git a/addons/account/wizard/account_invoice_refund.py b/addons/account/wizard/account_invoice_refund.py index 03c94b37d95..7f3ab878404 100644 --- a/addons/account/wizard/account_invoice_refund.py +++ b/addons/account/wizard/account_invoice_refund.py @@ -24,7 +24,7 @@ class AccountInvoiceRefund(models.TransientModel): date = fields.Date(string='Accounting Date') description = fields.Char(string='Reason', required=True, default=lambda self: self._get_reason()) refund_only = fields.Boolean(string='Technical field to hide filter_refund in case invoice is partially paid', compute='_get_refund_only') - filter_refund = fields.Selection([('refund', 'Create a draft credit note'), ('cancel', 'Cancel: create credit note and reconcile'), ('modify', 'Modify: create credit note, reconcile and create a new draft invoice')], + filter_refund = fields.Selection([('refund', 'Create a draft credit note (partial refunding)'), ('cancel', 'Cancel: create credit note and reconcile (full refunding)'), ('modify', 'Modify: create credit note, reconcile and create a new draft invoice')], default='refund', string='Credit Method', required=True, help='Choose how you want to credit this invoice. You cannot Modify and Cancel if the invoice is already reconciled') @api.depends('date_invoice')