From 64b340e5852ef340c9b6a4c3408e2792bb4fb93d Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Wed, 16 Nov 2016 15:46:45 +0100 Subject: [PATCH] Port account_usability to v10 --- account_usability/__init__.py | 2 +- account_usability/__manifest__.py | 31 +-- account_usability/account.py | 176 ++++++------------ account_usability/account_view.xml | 107 ++--------- .../migrations/8.0.0.2/pre-migration.py | 17 -- .../migrations/8.0.0.3/pre-migration.py | 16 -- stock_usability/__manifest__.py | 2 +- stock_usability/security/ir.model.access.csv | 1 + 8 files changed, 83 insertions(+), 269 deletions(-) delete mode 100644 account_usability/migrations/8.0.0.2/pre-migration.py delete mode 100644 account_usability/migrations/8.0.0.3/pre-migration.py diff --git a/account_usability/__init__.py b/account_usability/__init__.py index c6b3892..300089b 100644 --- a/account_usability/__init__.py +++ b/account_usability/__init__.py @@ -1,3 +1,3 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- from . import account diff --git a/account_usability/__manifest__.py b/account_usability/__manifest__.py index b11b213..219523f 100644 --- a/account_usability/__manifest__.py +++ b/account_usability/__manifest__.py @@ -1,29 +1,11 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# Account Usability module for Odoo -# Copyright (C) 2015 Akretion (http://www.akretion.com) -# @author Alexis de Lattre -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - +# -*- coding: utf-8 -*- +# © 2015-2016 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Account Usability', - 'version': '0.3', + 'version': '10.0.1.0.0', 'category': 'Accounting & Finance', 'license': 'AGPL-3', 'summary': 'Small usability enhancements in account module', @@ -48,7 +30,6 @@ This module has been written by Alexis de Lattre from Akretion -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2015-2016 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openerp import models, fields, api, _ -from openerp.tools import float_compare -from openerp.exceptions import Warning as UserError +from odoo import models, fields, api, _ +from odoo.tools import float_compare, float_is_zero +from odoo.exceptions import UserError class AccountInvoice(models.Model): _inherit = 'account.invoice' origin = fields.Char(track_visibility='onchange') - supplier_invoice_number = fields.Char(track_visibility='onchange') - internal_number = fields.Char(track_visibility='onchange') reference = fields.Char(track_visibility='onchange') sent = fields.Boolean(track_visibility='onchange') date_invoice = fields.Date(track_visibility='onchange') date_due = fields.Date(track_visibility='onchange') - payment_term = fields.Many2one(track_visibility='onchange') - period_id = fields.Many2one(track_visibility='onchange') + payment_term_id = fields.Many2one(track_visibility='onchange') account_id = fields.Many2one(track_visibility='onchange') journal_id = fields.Many2one(track_visibility='onchange') partner_bank_id = fields.Many2one(track_visibility='onchange') - fiscal_position = fields.Many2one(track_visibility='onchange') - - @api.multi - def onchange_payment_term_date_invoice(self, payment_term_id, date_invoice): - res = super(AccountInvoice, self).onchange_payment_term_date_invoice( - payment_term_id, date_invoice) - if res and isinstance(res, dict) and 'value' in res: - res['value']['period_id'] = False - return res + fiscal_position_id = fields.Many2one(track_visibility='onchange') # I really hate to see a "/" in the 'name' field of the account.move.line # generated from customer invoices linked to the partners' account because: @@ -56,26 +28,32 @@ class AccountInvoice(models.Model): # write a rubbish '/' in it ! # 2) the 'name' field of the account.move.line is used in the overdue letter, # and '/' is not meaningful for our customer ! - @api.multi - def action_number(self): - res = super(AccountInvoice, self).action_number() - for inv in self: - self._cr.execute( - "UPDATE account_move_line SET name= " - "CASE WHEN name='/' THEN %s " - "ELSE %s||' - '||name END " - "WHERE move_id=%s", (inv.number, inv.number, inv.move_id.id)) - self.invalidate_cache() - return res + # TODO port to v10 + #@api.multi + #def action_number(self): + # res = super(AccountInvoice, self).action_number() + # for inv in self: + # self._cr.execute( + # "UPDATE account_move_line SET name= " + # "CASE WHEN name='/' THEN %s " + # "ELSE %s||' - '||name END " + # "WHERE move_id=%s", (inv.number, inv.number, inv.move_id.id)) + # self.invalidate_cache() + # return res -class AccountFiscalYear(models.Model): - _inherit = 'account.fiscalyear' +class AccountInvoiceLine(models.Model): + _inherit = 'account.invoice.line' - # For companies that have a fiscal year != calendar year - # I want to be able to write '2015-2016' in the code field - # => size=9 instead of 6 - code = fields.Char(size=9) + # In the 'account' module, we have related stored field for: + # company_id, partner_id, currency_id + type = fields.Selection( + related='invoice_id.type', store=True, readonly=True) + date_invoice = fields.Date( + related='invoice_id.date_invoice', store=True, readonly=True) + commercial_partner_id = fields.Many2one( + related='invoice_id.commercial_partner_id', + store=True, readonly=True) class AccountJournal(models.Model): @@ -122,35 +100,33 @@ class AccountAnalyticAccount(models.Model): return super(AccountAnalyticAccount, self).name_get() -class AccountMove(models.Model): - _inherit = 'account.move' - - @api.onchange('date') - def date_onchange(self): - if self.date: - self.period_id = self.env['account.period'].find(self.date) - - class AccountMoveLine(models.Model): _inherit = 'account.move.line' @api.onchange('credit') def _credit_onchange(self): - if self.credit and self.debit: + prec = self.env['decimal.precision'].precision_get('Account') + if ( + not float_is_zero(self.credit, precision_digits=prec) and + not float_is_zero(self.debit, precision_digits=prec)): self.debit = 0 @api.onchange('debit') def _debit_onchange(self): - if self.debit and self.credit: + prec = self.env['decimal.precision'].precision_get('Account') + if ( + not float_is_zero(self.debit, precision_digits=prec) and + not float_is_zero(self.credit, precision_digits=prec)): self.credit = 0 @api.onchange('currency_id', 'amount_currency') def _amount_currency_change(self): + prec = self.env['decimal.precision'].precision_get('Account') if ( self.currency_id and self.amount_currency and - not self.credit and - not self.debit): + float_is_zero(self.credit, precision_digits=prec) and + float_is_zero(self.debit, precision_digits=prec)): date = self.date or None amount_company_currency = self.currency_id.with_context( date=date).compute( @@ -182,77 +158,35 @@ class AccountBankStatementLine(models.Model): # figure out that the fact that the user can't find move line 'x' # is caused by this. # Set search_reconciliation_proposition to False by default - def get_data_for_reconciliations( - self, cr, uid, ids, excluded_ids=None, - search_reconciliation_proposition=False, context=None): - # Make variable name shorted for PEP8 ! - search_rec_prop = search_reconciliation_proposition - return super(AccountBankStatementLine, self).\ - get_data_for_reconciliations( - cr, uid, ids, excluded_ids=excluded_ids, - search_reconciliation_proposition=search_rec_prop, - context=context) + # TODO: re-write in v10 + #def get_data_for_reconciliations( + # self, cr, uid, ids, excluded_ids=None, + # search_reconciliation_proposition=False, context=None): + # # Make variable name shorted for PEP8 ! + # search_rec_prop = search_reconciliation_proposition + # return super(AccountBankStatementLine, self).\ + # get_data_for_reconciliations( + # cr, uid, ids, excluded_ids=excluded_ids, + # search_reconciliation_proposition=search_rec_prop, + # context=context) @api.multi def show_account_move(self): self.ensure_one() action = self.env['ir.actions.act_window'].for_xml_id( 'account', 'action_move_journal_line') - if self.journal_entry_id: + if self.journal_entry_ids: action.update({ 'views': False, 'view_id': False, 'view_mode': 'form,tree', - 'res_id': self.journal_entry_id.id, + 'res_id': self.journal_entry_ids[0].id, }) return action else: raise UserError(_( 'No journal entry linked to this bank statement line.')) -class ResPartner(models.Model): - _inherit = 'res.partner' - - @api.multi - def show_receivable_account(self): - self.ensure_one() - account_id = self.property_account_receivable.id - return self.common_show_account(self.ids[0], account_id) - - @api.multi - def show_payable_account(self): - self.ensure_one() - account_id = self.property_account_payable.id - return self.common_show_account(self.ids[0], account_id) - - def common_show_account(self, partner_id, account_id): - action = self.env['ir.actions.act_window'].for_xml_id( - 'account', 'action_account_moves_all_tree') - action['context'] = { - 'search_default_partner_id': [partner_id], - 'default_partner_id': partner_id, - 'search_default_account_id': account_id, - } - return action - - @api.multi - def _compute_journal_item_count(self): - amlo = self.env['account.move.line'] - for partner in self: - partner.journal_item_count = amlo.search_count([ - ('partner_id', '=', partner.id), - ('account_id', '=', partner.property_account_receivable.id)]) - partner.payable_journal_item_count = amlo.search_count([ - ('partner_id', '=', partner.id), - ('account_id', '=', partner.property_account_payable.id)]) - - journal_item_count = fields.Integer( - compute='_compute_journal_item_count', - string="Journal Items", readonly=True) - payable_journal_item_count = fields.Integer( - compute='_compute_journal_item_count', - string="Payable Journal Items", readonly=True) - class AccountFiscalPosition(models.Model): _inherit = 'account.fiscal.position' diff --git a/account_usability/account_view.xml b/account_usability/account_view.xml index 49a68a9..f76ed76 100644 --- a/account_usability/account_view.xml +++ b/account_usability/account_view.xml @@ -1,12 +1,11 @@ - - + @@ -14,14 +13,9 @@ account.invoice - + selection - - - - @@ -30,14 +24,9 @@ account.invoice - + selection - - - - @@ -46,25 +35,12 @@ account.invoice - - + + not context.get('type') in ('in_invoice', 'in_refund') - - account_usability.invoice.search - account.invoice - - - - - - - - 200 @@ -77,35 +53,29 @@ 200 + account_usability.account_move_line_search account.move.line + Name or Reference @@ -123,15 +93,12 @@ - + account_usability.account_type_tree account.account.type - - - - - - - - usability.res.partner.journal.items.button - res.partner - - - - - - - Receivable Account + + @@ -197,11 +129,10 @@