diff options
| author | Yannick Tivisse <yti@odoo.com> | 2016-08-05 15:29:54 +0200 |
|---|---|---|
| committer | Yannick Tivisse <yti@odoo.com> | 2016-08-08 12:24:40 +0200 |
| commit | d6e1d41128c126071d697220f1c83495d6cabc71 (patch) | |
| tree | 919f0028eb0162b5efd3baf211d8679456f9ccc5 /addons/account/models | |
| parent | 5177186f437cfc14753a3d7c444fc2b68cf42d83 (diff) | |
[MIG] account: Migrate remaining old API chuncks of code
Diffstat (limited to 'addons/account/models')
| -rw-r--r-- | addons/account/models/account.py | 21 | ||||
| -rw-r--r-- | addons/account/models/account_analytic_line.py | 2 | ||||
| -rw-r--r-- | addons/account/models/account_bank_statement.py | 25 | ||||
| -rw-r--r-- | addons/account/models/account_invoice.py | 35 | ||||
| -rw-r--r-- | addons/account/models/account_journal_dashboard.py | 18 | ||||
| -rw-r--r-- | addons/account/models/account_move.py | 38 | ||||
| -rw-r--r-- | addons/account/models/account_payment.py | 4 | ||||
| -rw-r--r-- | addons/account/models/chart_template.py | 39 | ||||
| -rw-r--r-- | addons/account/models/company.py | 2 | ||||
| -rw-r--r-- | addons/account/models/partner.py | 42 | ||||
| -rw-r--r-- | addons/account/models/product.py | 4 | ||||
| -rw-r--r-- | addons/account/models/res_config.py | 10 | ||||
| -rw-r--r-- | addons/account/models/web_planner.py | 2 |
13 files changed, 96 insertions, 146 deletions
diff --git a/addons/account/models/account.py b/addons/account/models/account.py index 637c26083ee..c77a9fb00b8 100644 --- a/addons/account/models/account.py +++ b/addons/account/models/account.py @@ -3,11 +3,11 @@ import time import math -from openerp.osv import expression -from openerp.tools.float_utils import float_round as round -from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT -from openerp.exceptions import UserError, ValidationError -from openerp import api, fields, models, _ +from odoo.osv import expression +from odoo.tools.float_utils import float_round as round +from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT +from odoo.exceptions import UserError, ValidationError +from odoo import api, fields, models, _ class AccountAccountType(models.Model): @@ -642,7 +642,7 @@ class AccountTax(models.Model): if self.amount_type == 'division' and not self.price_include: return base_amount / (1 - self.amount / 100) - base_amount - @api.v8 + @api.multi def compute_all(self, price_unit, currency=None, quantity=1.0, product=None, partner=None): """ Returns all information required to apply taxes (in self + their children in case of a tax goup). We consider the sequence of the parent for group of taxes. @@ -729,15 +729,6 @@ class AccountTax(models.Model): 'base': base, } - @api.v7 - def compute_all(self, cr, uid, ids, price_unit, currency_id=None, quantity=1.0, product_id=None, partner_id=None, context=None): - currency = currency_id and self.pool.get('res.currency').browse(cr, uid, currency_id, context=context) or None - product = product_id and self.pool.get('product.product').browse(cr, uid, product_id, context=context) or None - partner = partner_id and self.pool.get('res.partner').browse(cr, uid, partner_id, context=context) or None - ids = isinstance(ids, (int, long)) and [ids] or ids - recs = self.browse(cr, uid, ids, context=context) - return AccountTax.compute_all(recs, price_unit, currency, quantity, product, partner) - @api.model def _fix_tax_included_price(self, price, prod_taxes, line_taxes): """Subtract tax amount from price when corresponding "price included" taxes do not apply""" diff --git a/addons/account/models/account_analytic_line.py b/addons/account/models/account_analytic_line.py index b7120d0c907..1578d237500 100644 --- a/addons/account/models/account_analytic_line.py +++ b/addons/account/models/account_analytic_line.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from openerp import api, fields, models, _ +from odoo import api, fields, models, _ class AccountAnalyticLine(models.Model): diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index fcd3bcaa9e5..6df4e8f5c9d 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -1,11 +1,11 @@ # -*- coding: utf-8 -*- -from openerp import api, fields, models, _ -from openerp.osv import expression -from openerp.tools import float_is_zero -from openerp.tools import float_compare, float_round -from openerp.tools.misc import formatLang -from openerp.exceptions import UserError, ValidationError +from odoo import api, fields, models, _ +from odoo.osv import expression +from odoo.tools import float_is_zero +from odoo.tools import float_compare, float_round +from odoo.tools.misc import formatLang +from odoo.exceptions import UserError, ValidationError import time import math @@ -769,19 +769,18 @@ class AccountBankStatementLine(models.Model): 'amount_currency': amount_currency, } - @api.v7 - def process_reconciliations(self, cr, uid, ids, data, context=None): + @api.multi + def process_reconciliations(self, data): """ Handles data sent from the bank statement reconciliation widget (and can otherwise serve as an old-API bridge) :param list of dicts data: must contains the keys 'counterpart_aml_dicts', 'payment_aml_ids' and 'new_aml_dicts', whose value is the same as described in process_reconciliation except that ids are used instead of recordsets. """ - aml_obj = self.pool['account.move.line'] - for id, datum in zip(ids, data): - st_line = self.browse(cr, uid, id, context) - payment_aml_rec = aml_obj.browse(cr, uid, datum.get('payment_aml_ids', []), context) + AccountMoveLine = self.env['account.move.line'] + for st_line, datum in zip(self, data): + payment_aml_rec = AccountMoveLine.browse(datum.get('payment_aml_ids', [])) for aml_dict in datum.get('counterpart_aml_dicts', []): - aml_dict['move_line'] = aml_obj.browse(cr, uid, aml_dict['counterpart_aml_id'], context) + aml_dict['move_line'] = AccountMoveLine.browse(aml_dict['counterpart_aml_id']) del aml_dict['counterpart_aml_id'] st_line.process_reconciliation(datum.get('counterpart_aml_dicts', []), payment_aml_rec, datum.get('new_aml_dicts', [])) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 6fe9a217aa6..1623af869eb 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -5,13 +5,13 @@ from lxml import etree from datetime import datetime from dateutil.relativedelta import relativedelta -from openerp import api, fields, models, _ -from openerp.tools import float_is_zero, float_compare -from openerp.tools.misc import formatLang +from odoo import api, fields, models, _ +from odoo.tools import float_is_zero, float_compare +from odoo.tools.misc import formatLang -from openerp.exceptions import UserError, RedirectWarning, ValidationError +from odoo.exceptions import UserError, RedirectWarning, ValidationError -import openerp.addons.decimal_precision as dp +import odoo.addons.decimal_precision as dp # mapping invoice type to journal type TYPE2JOURNAL = { @@ -585,17 +585,17 @@ class AccountInvoice(models.Model): line_to_reconcile += inv.move_id.line_ids.filtered(lambda r: not r.reconciled and r.account_id.internal_type in ('payable', 'receivable')) return (line_to_reconcile + payment_line).reconcile(writeoff_acc_id, writeoff_journal_id) - @api.v7 - def assign_outstanding_credit(self, cr, uid, id, credit_aml_id, context=None): - credit_aml = self.pool.get('account.move.line').browse(cr, uid, credit_aml_id, context=context) - inv = self.browse(cr, uid, id, context=context) - if not credit_aml.currency_id and inv.currency_id != inv.company_id.currency_id: + @api.multi + def assign_outstanding_credit(self, credit_aml_id): + self.ensure_one() + credit_aml = self.env['account.move.line'].browse(credit_aml_id) + if not credit_aml.currency_id and self.currency_id != self.company_id.currency_id: credit_aml.with_context(allow_amount_currency=True).write({ - 'amount_currency': inv.company_id.currency_id.with_context(date=credit_aml.date).compute(credit_aml.balance, inv.currency_id), - 'currency_id': inv.currency_id.id}) + 'amount_currency': self.company_id.currency_id.with_context(date=credit_aml.date).compute(credit_aml.balance, self.currency_id), + 'currency_id': self.currency_id.id}) if credit_aml.payment_id: credit_aml.payment_id.write({'invoice_ids': [(4, id, None)]}) - return inv.register_payment(credit_aml) + return self.register_payment(credit_aml) @api.multi def action_date_assign(self): @@ -998,7 +998,7 @@ class AccountInvoice(models.Model): new_invoices += refund_invoice return new_invoices - @api.v8 + @api.multi def pay_and_reconcile(self, pay_journal, pay_amount=None, date=None, writeoff_acc=None): """ Create and post an account.payment for the invoice self, which creates a journal entry that reconciles the invoice. @@ -1033,13 +1033,6 @@ class AccountInvoice(models.Model): }) payment.post() - @api.v7 - def pay_and_reconcile(self, cr, uid, ids, pay_journal_id, pay_amount=None, date=None, writeoff_acc_id=None, context=None): - recs = self.browse(cr, uid, ids, context) - pay_journal = self.pool.get('account.journal').browse(cr, uid, pay_journal_id, context=context) - writeoff_acc = self.pool.get('account.account').browse(cr, uid, writeoff_acc_id, context=context) - return AccountInvoice.pay_and_reconcile(recs, pay_journal, pay_amount, date, writeoff_acc) - @api.multi def _track_subtype(self, init_values): self.ensure_one() diff --git a/addons/account/models/account_journal_dashboard.py b/addons/account/models/account_journal_dashboard.py index 84b449d6b8d..b3f0883da05 100644 --- a/addons/account/models/account_journal_dashboard.py +++ b/addons/account/models/account_journal_dashboard.py @@ -3,9 +3,9 @@ from datetime import datetime, timedelta from babel.dates import format_datetime, format_date -from openerp import models, api, _, fields -from openerp.tools import DEFAULT_SERVER_DATE_FORMAT as DF -from openerp.tools.misc import formatLang +from odoo import models, api, _, fields +from odoo.tools import DEFAULT_SERVER_DATE_FORMAT as DF +from odoo.tools.misc import formatLang class account_journal(models.Model): _inherit = "account.journal" @@ -311,9 +311,7 @@ class account_journal(models.Model): 'default_type': invoice_type, 'type': invoice_type }) - ir_model_obj = self.pool['ir.model.data'] - model, action_id = ir_model_obj.get_object_reference(self._cr, self._uid, 'account', action_name) - action = self.pool[model].read(self._cr, self._uid, action_id, context=self._context) + [action] = self.env.ref('account.%s' % action_name).read() action['context'] = ctx action['domain'] = self._context.get('use_domain', []) return action @@ -352,13 +350,13 @@ class account_journal(models.Model): ctx = dict(self.env.context, default_journal_id=self.id) if ctx.get('search_default_journal', False): ctx.update(search_default_journal_id=self.id) - ir_model_obj = self.pool['ir.model.data'] - model, action_id = ir_model_obj.get_object_reference(self._cr, self._uid, 'account', action_name) - action = self.pool[model].read(self._cr, self._uid, action_id, context=self._context) + ir_model_obj = self.env['ir.model.data'] + model, action_id = ir_model_obj.get_object_reference('account', action_name) + [action] = self.env[model].browse(action_id).read() action['context'] = ctx if ctx.get('use_domain', False): action['domain'] = ['|', ('journal_id', '=', self.id), ('journal_id', '=', False)] - action['name'] += ' for journal '+self.name + action['name'] += ' for journal ' + self.name return action @api.multi diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 4de95ac4dfc..a9e8087f0a6 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -2,12 +2,12 @@ import time from collections import OrderedDict -from openerp import api, fields, models, _ -from openerp.osv import expression -from openerp.exceptions import RedirectWarning, UserError, ValidationError -from openerp.tools.misc import formatLang -from openerp.tools import float_is_zero, float_compare -from openerp.tools.safe_eval import safe_eval +from odoo import api, fields, models, _ +from odoo.osv import expression +from odoo.exceptions import RedirectWarning, UserError, ValidationError +from odoo.tools.misc import formatLang +from odoo.tools import float_is_zero, float_compare +from odoo.tools.safe_eval import safe_eval from lxml import etree #---------------------------------------------------------- @@ -633,13 +633,7 @@ class AccountMoveLine(models.Model): target_currency = account.currency_id or account.company_id.currency_id return lines.prepare_move_lines_for_reconciliation_widget(target_currency=target_currency) - @api.v7 - def prepare_move_lines_for_reconciliation_widget(self, cr, uid, line_ids, target_currency_id=False, context=None): - recs = self.browse(cr, uid, line_ids, context) - target_currency = target_currency_id and self.pool.get('res.currency').browse(cr, uid, target_currency_id, context=context) or False - return AccountMoveLine.prepare_move_lines_for_reconciliation_widget(recs, target_currency=target_currency) - - @api.v8 + @api.multi def prepare_move_lines_for_reconciliation_widget(self, target_currency=False, target_date=False): """ Returns move lines formatted for the manual/bank reconciliation widget @@ -712,8 +706,8 @@ class AccountMoveLine(models.Model): ret.append(ret_line) return ret - @api.v7 - def process_reconciliations(self, cr, uid, data, context=None): + @api.model + def process_reconciliations(self, data): """ Used to validate a batch of reconciliations in a single call :param data: list of dicts containing: - 'type': either 'partner' or 'account' @@ -723,14 +717,14 @@ class AccountMoveLine(models.Model): """ for datum in data: if len(datum['mv_line_ids']) >= 1 or len(datum['mv_line_ids']) + len(datum['new_mv_line_dicts']) >= 2: - self.process_reconciliation(cr, uid, datum['mv_line_ids'], datum['new_mv_line_dicts'], context=context) + self.process_reconciliation(datum['mv_line_ids'], datum['new_mv_line_dicts']) if datum['type'] == 'partner': - partners = self.pool['res.partner'].browse(cr, uid, datum['id'], context=context) - self.pool['res.partner'].mark_as_reconciled(cr, uid, partners.ids, context=context) + partners = self.env['res.partner'].browse(datum['id']) + partners.mark_as_reconciled() if datum['type'] == 'account': - accounts = self.pool['account.account'].browse(cr, uid, datum['id'], context=context) - self.pool['account.account'].mark_as_reconciled(cr, uid, accounts.ids, context=context) + accounts = self.env['account.account'].browse(datum['id']) + accounts.mark_as_reconciled() @api.multi def process_reconciliation(self, new_mv_line_dicts): @@ -1035,7 +1029,6 @@ class AccountMoveLine(models.Model): if not move_id: if not vals.get('move_id', False): if journal.sequence_id: - #name = self.pool.get('ir.sequence').next_by_id(cr, uid, journal.sequence_id.id) v = { 'date': vals.get('date', time.strftime('%Y-%m-%d')), 'journal_id': context['journal_id'] @@ -1299,8 +1292,7 @@ class AccountMoveLine(models.Model): @api.multi def open_reconcile_view(self): - model, action_id = self.pool['ir.model.data'].get_object_reference(self._cr, self._uid, 'account', "action_account_moves_all_a") - action = self.pool[model].read(self._cr, self._uid, action_id, context=self._context) + [action] = self.env.ref('account.action_account_moves_all_a').read() ids = [] for aml in self: if aml.account_id.reconcile: diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index cd3a26874c4..496f0a56bae 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- -from openerp import models, fields, api, _ -from openerp.exceptions import UserError, ValidationError +from odoo import models, fields, api, _ +from odoo.exceptions import UserError, ValidationError MAP_INVOICE_TYPE_PARTNER_TYPE = { 'out_invoice': 'customer', diff --git a/addons/account/models/chart_template.py b/addons/account/models/chart_template.py index 7258e087f28..c74fdd7f702 100644 --- a/addons/account/models/chart_template.py +++ b/addons/account/models/chart_template.py @@ -1,15 +1,8 @@ # -*- coding: utf-8 -*- -import time -import math - -from openerp.osv import expression -from openerp.tools.float_utils import float_round as round -from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT -from openerp.exceptions import AccessError, UserError, ValidationError -import openerp.addons.decimal_precision as dp -from openerp import api, fields, models, _ -from openerp import SUPERUSER_ID +from odoo.exceptions import AccessError +from odoo import api, fields, models, _ +from odoo import SUPERUSER_ID import logging _logger = logging.getLogger(__name__) @@ -18,7 +11,11 @@ def migrate_set_tags_and_taxes_updatable(cr, registry, module): ''' This is a utility function used to manually set the flag noupdate to False on tags and account tax templates on localization modules that need migration (for example in case of VAT report improvements) ''' - xml_record_ids = registry['ir.model.data'].search(cr, SUPERUSER_ID, [('model', 'in', ['account.tax.template', 'account.account.tag']), ('module', 'like', module)]) + env = api.Environment(cr, SUPERUSER_ID, {}) + xml_record_ids = env['ir.model.data'].search([ + ('model', 'in', ['account.tax.template', 'account.account.tag']), + ('module', 'like', module) + ]).ids if xml_record_ids: cr.execute("update ir_model_data set noupdate = 'f' where id in %s", (tuple(xml_record_ids),)) @@ -29,12 +26,20 @@ def migrate_tags_on_taxes(cr, registry): Note: This unusual decision has been made in order to help the improvement of VAT reports on version 9.0, to have them more flexible and working out of the box when people are creating/using new taxes. ''' - xml_record_ids = registry['ir.model.data'].search(cr, SUPERUSER_ID, [('model', '=', 'account.tax.template'), ('module', 'like', 'l10n_%')]) - tax_template_ids = [x['res_id'] for x in registry['ir.model.data'].read(cr, SUPERUSER_ID, xml_record_ids, ['res_id'])] - for tax_template in registry['account.tax.template'].browse(cr, SUPERUSER_ID, tax_template_ids): - tax_id = registry['account.tax'].search(cr, SUPERUSER_ID, [('name', '=', tax_template.name), ('type_tax_use', '=', tax_template.type_tax_use), ('description', '=', tax_template.description)]) - if len(tax_id) == 1: - registry['account.tax'].write(cr, SUPERUSER_ID, tax_id, {'tag_ids': [(6,0,[x.id for x in tax_template.tag_ids])]}) + env = api.Environment(cr, SUPERUSER_ID, {}) + xml_records = env['ir.model.data'].search([ + ('model', '=', 'account.tax.template'), + ('module', 'like', 'l10n_%') + ]) + tax_template_ids = [x['res_id'] for x in xml_records.sudo().read(['res_id'])] + for tax_template in env['account.tax.template'].browse(tax_template_ids): + tax_id = env['account.tax'].search([ + ('name', '=', tax_template.name), + ('type_tax_use', '=', tax_template.type_tax_use), + ('description', '=', tax_template.description) + ]) + if len(tax_id.ids) == 1: + tax_id.sudo().write({'tag_ids': [(6, 0, [tax_template.tag_ids.ids])]}) # --------------------------------------------------------------- # Account Templates: Account, Tax, Tax Code and chart. + Wizard diff --git a/addons/account/models/company.py b/addons/account/models/company.py index faa20059bc4..d4ed009ccdc 100644 --- a/addons/account/models/company.py +++ b/addons/account/models/company.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from openerp import fields, models, api, _ +from odoo import fields, models, api, _ from datetime import timedelta diff --git a/addons/account/models/partner.py b/addons/account/models/partner.py index fb879b85e9f..faa6b147da1 100644 --- a/addons/account/models/partner.py +++ b/addons/account/models/partner.py @@ -3,10 +3,10 @@ from operator import itemgetter import time -from openerp import api, fields, models, _ -from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT -from openerp.exceptions import ValidationError -from openerp.addons.base.res.res_partner import WARNING_MESSAGE, WARNING_HELP +from odoo import api, fields, models, _ +from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT +from odoo.exceptions import ValidationError +from odoo.addons.base.res.res_partner import WARNING_MESSAGE, WARNING_HELP class AccountFiscalPosition(models.Model): _name = 'account.fiscal.position' @@ -44,25 +44,7 @@ class AccountFiscalPosition(models.Model): raise ValidationError(_('Invalid "Zip Range", please configure it properly.')) return True - @api.v7 - def map_tax(self, cr, uid, fposition_id, taxes, product=None, partner=None, context=None): - if not taxes: - return [] - if not fposition_id: - return map(lambda x: x.id, taxes) - result = set() - for t in taxes: - ok = False - for tax in fposition_id.tax_ids: - if tax.tax_src_id.id == t.id: - if tax.tax_dest_id: - result.add(tax.tax_dest_id.id) - ok = True - if not ok: - result.add(t.id) - return list(result) - - @api.v8 # noqa + @api.model # noqa def map_tax(self, taxes, product=None, partner=None): result = self.env['account.tax'].browse() for tax in taxes: @@ -76,24 +58,14 @@ class AccountFiscalPosition(models.Model): result |= tax return result - @api.v7 - def map_account(self, cr, uid, fposition_id, account_id, context=None): - if not fposition_id: - return account_id - for pos in fposition_id.account_ids: - if pos.account_src_id.id == account_id: - account_id = pos.account_dest_id.id - break - return account_id - - @api.v8 + @api.model def map_account(self, account): for pos in self.account_ids: if pos.account_src_id == account: return pos.account_dest_id return account - @api.v8 + @api.model def map_accounts(self, accounts): """ Receive a dictionary having accounts in values and try to replace those accounts accordingly to the fiscal position. """ diff --git a/addons/account/models/product.py b/addons/account/models/product.py index b411ae50f15..117cb5ae826 100644 --- a/addons/account/models/product.py +++ b/addons/account/models/product.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- -from openerp import api, fields, models, _ -from openerp.exceptions import UserError +from odoo import api, fields, models, _ +from odoo.exceptions import UserError class ProductCategory(models.Model): diff --git a/addons/account/models/res_config.py b/addons/account/models/res_config.py index 778d5cd1460..76de3db1d25 100644 --- a/addons/account/models/res_config.py +++ b/addons/account/models/res_config.py @@ -4,11 +4,11 @@ import time import datetime from dateutil.relativedelta import relativedelta -import openerp -from openerp import SUPERUSER_ID -from openerp.tools import DEFAULT_SERVER_DATE_FORMAT as DF -from openerp import api, fields, models, _ -from openerp.exceptions import UserError +import odoo +from odoo import SUPERUSER_ID +from odoo.tools import DEFAULT_SERVER_DATE_FORMAT as DF +from odoo import api, fields, models, _ +from odoo.exceptions import UserError class AccountConfigSettings(models.TransientModel): diff --git a/addons/account/models/web_planner.py b/addons/account/models/web_planner.py index b5ecbaa7008..40e7f44676e 100644 --- a/addons/account/models/web_planner.py +++ b/addons/account/models/web_planner.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from openerp import api, models +from odoo import api, models class PlannerAccount(models.Model): |
