[IMP] *: avoid non-stored dependencies

This commit is contained in:
Raphael Collet
2018-01-12 15:00:01 +01:00
parent ca9d2b3006
commit 2304edd46c
7 changed files with 19 additions and 11 deletions
@@ -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):
+1 -1
View File
@@ -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')
+1 -1
View File
@@ -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(
@@ -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')
+2 -2
View File
@@ -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)
+1 -1
View File
@@ -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):
+1 -1
View File
@@ -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')