From 2304edd46cc12aaef4fddaa22887ff51f51581bc Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Fri, 12 Jan 2018 14:12:43 +0100 Subject: [PATCH] [IMP] *: avoid non-stored dependencies --- addons/account_voucher/models/account_voucher.py | 14 +++++++++++--- addons/delivery/models/stock_picking.py | 2 +- addons/hr/models/hr.py | 2 +- addons/l10n_be_hr_payroll_fleet/models/fleet.py | 4 ++-- addons/repair/models/repair.py | 4 ++-- addons/resource/models/resource_mixin.py | 2 +- addons/sale/models/sale.py | 2 +- 7 files changed, 19 insertions(+), 11 deletions(-) diff --git a/addons/account_voucher/models/account_voucher.py b/addons/account_voucher/models/account_voucher.py index f6fc6efbf27..aac79a719f4 100644 --- a/addons/account_voucher/models/account_voucher.py +++ b/addons/account_voucher/models/account_voucher.py @@ -4,7 +4,7 @@ from odoo import fields, models, api, _ from odoo.addons import decimal_precision as dp -from odoo.exceptions import UserError +from odoo.exceptions import UserError, ValidationError class AccountVoucher(models.Model): @@ -45,9 +45,9 @@ class AccountVoucher(models.Model): states={'draft': [('readonly', False)]}) narration = fields.Text('Notes', readonly=True, states={'draft': [('readonly', False)]}) currency_id = fields.Many2one('res.currency', compute='_get_journal_currency', - string='Currency', readonly=True, required=True, default=lambda self: self._get_currency()) + string='Currency', readonly=True, store=True, default=lambda self: self._get_currency()) company_id = fields.Many2one('res.company', 'Company', - required=True, readonly=True, states={'draft': [('readonly', False)]}, + store=True, readonly=True, states={'draft': [('readonly', False)]}, related='journal_id.company_id', default=lambda self: self._get_company()) state = fields.Selection([ ('draft', 'Draft'), @@ -91,6 +91,14 @@ class AccountVoucher(models.Model): def _get_company(self): return self._context.get('company_id', self.env.user.company_id.id) + @api.constrains('company_id', 'currency_id') + def _check_company_id(self): + for voucher in self: + if not voucher.company_id: + raise ValidationError(_("Missing Company")) + if not voucher.currency_id: + raise ValidationError(_("Missing Currency")) + @api.multi @api.depends('name', 'number') def name_get(self): diff --git a/addons/delivery/models/stock_picking.py b/addons/delivery/models/stock_picking.py index 09ff971bed0..e7e5dfa5e23 100644 --- a/addons/delivery/models/stock_picking.py +++ b/addons/delivery/models/stock_picking.py @@ -99,7 +99,7 @@ class StockPicking(models.Model): for picking in self: picking.carrier_tracking_url = picking.carrier_id.get_tracking_link(picking) if picking.carrier_id and picking.carrier_tracking_ref else False - @api.depends('product_id', 'move_lines') + @api.depends('move_lines') def _cal_weight(self): for picking in self: picking.weight = sum(move.weight for move in picking.move_lines if move.state != 'cancel') diff --git a/addons/hr/models/hr.py b/addons/hr/models/hr.py index ea1716326a7..df69b49e3f4 100644 --- a/addons/hr/models/hr.py +++ b/addons/hr/models/hr.py @@ -107,7 +107,7 @@ class Employee(models.Model): # resource and user # required on the resource, make sure required="True" set in the view name = fields.Char(related='resource_id.name', store=True, oldname='name_related') - user_id = fields.Many2one('res.users', 'User', related='resource_id.user_id') + user_id = fields.Many2one('res.users', 'User', related='resource_id.user_id', store=True) active = fields.Boolean('Active', related='resource_id.active', default=True, store=True) # private partner address_home_id = fields.Many2one( diff --git a/addons/l10n_be_hr_payroll_fleet/models/fleet.py b/addons/l10n_be_hr_payroll_fleet/models/fleet.py index 2580fae49c1..58b938ac934 100644 --- a/addons/l10n_be_hr_payroll_fleet/models/fleet.py +++ b/addons/l10n_be_hr_payroll_fleet/models/fleet.py @@ -11,8 +11,8 @@ from odoo.fields import Datetime class FleetVehicle(models.Model): _inherit = 'fleet.vehicle' - co2_fee = fields.Float(compute='_compute_co2_fee', string="CO2 Fee") - total_depreciated_cost = fields.Float(compute='_compute_total_depreciated_cost', + co2_fee = fields.Float(compute='_compute_co2_fee', string="CO2 Fee", store=True) + total_depreciated_cost = fields.Float(compute='_compute_total_depreciated_cost', store=True, string="Total Cost (Depreciated)", help="This includes all the depreciated costs and the CO2 fee") total_cost = fields.Float(compute='_compute_total_cost', string="Total Cost", help="This include all the costs and the CO2 fee") fuel_type = fields.Selection(required=True, default='diesel') diff --git a/addons/repair/models/repair.py b/addons/repair/models/repair.py index c8c9ff23596..5ec5704214a 100644 --- a/addons/repair/models/repair.py +++ b/addons/repair/models/repair.py @@ -504,7 +504,7 @@ class RepairLine(models.Model): product_id = fields.Many2one('product.product', 'Product', required=True) invoiced = fields.Boolean('Invoiced', copy=False, readonly=True) price_unit = fields.Float('Unit Price', required=True, digits=dp.get_precision('Product Price')) - price_subtotal = fields.Float('Subtotal', compute='_compute_price_subtotal', digits=0) + price_subtotal = fields.Float('Subtotal', compute='_compute_price_subtotal', store=True, digits=0) tax_id = fields.Many2many( 'account.tax', 'repair_operation_line_tax', 'repair_operation_line_id', 'tax_id', 'Taxes') product_uom_qty = fields.Float( @@ -616,7 +616,7 @@ class RepairFee(models.Model): product_uom_qty = fields.Float('Quantity', digits=dp.get_precision('Product Unit of Measure'), required=True, default=1.0) price_unit = fields.Float('Unit Price', required=True) product_uom = fields.Many2one('product.uom', 'Product Unit of Measure', required=True) - price_subtotal = fields.Float('Subtotal', compute='_compute_price_subtotal', digits=0) + price_subtotal = fields.Float('Subtotal', compute='_compute_price_subtotal', store=True, digits=0) tax_id = fields.Many2many('account.tax', 'repair_fee_line_tax', 'repair_fee_line_id', 'tax_id', 'Taxes') invoice_line_id = fields.Many2one('account.invoice.line', 'Invoice Line', copy=False, readonly=True) invoiced = fields.Boolean('Invoiced', copy=False, readonly=True) diff --git a/addons/resource/models/resource_mixin.py b/addons/resource/models/resource_mixin.py index fd531467998..416bd2875e7 100644 --- a/addons/resource/models/resource_mixin.py +++ b/addons/resource/models/resource_mixin.py @@ -20,7 +20,7 @@ class ResourceMixin(models.AbstractModel): resource_calendar_id = fields.Many2one( 'resource.calendar', 'Working Hours', default=lambda self: self.env['res.company']._company_default_get().resource_calendar_id, - index=True, related='resource_id.calendar_id') + index=True, related='resource_id.calendar_id', store=True) @api.model def create(self, values): diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index fccd37d4e5f..24231933aa4 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -882,7 +882,7 @@ class SaleOrderLine(models.Model): digits=dp.get_precision('Product Unit of Measure')) salesman_id = fields.Many2one(related='order_id.user_id', store=True, string='Salesperson', readonly=True) - currency_id = fields.Many2one(related='order_id.currency_id', store=True, string='Currency', readonly=True) + currency_id = fields.Many2one(related='order_id.currency_id', depends=['order_id'], store=True, string='Currency', readonly=True) company_id = fields.Many2one(related='order_id.company_id', string='Company', store=True, readonly=True) order_partner_id = fields.Many2one(related='order_id.partner_id', store=True, string='Customer') analytic_tag_ids = fields.Many2many('account.analytic.tag', string='Analytic Tags')