diff --git a/stock_request_analytic/models/procurement_rule.py b/stock_request_analytic/models/procurement_rule.py index c39d295cb..e09a0800e 100644 --- a/stock_request_analytic/models/procurement_rule.py +++ b/stock_request_analytic/models/procurement_rule.py @@ -12,7 +12,8 @@ class ProcurementRule(models.Model): res = super(ProcurementRule, self)._get_stock_move_values( product_id, product_qty, product_uom, location_id, name, origin, values, group_id) - analytic_account_id = self.env['stock.request'].browse( - values['stock_request_id']).analytic_account_id.id - res.update(analytic_account_id=analytic_account_id) + if values.get('stock_request_id'): + analytic_account_id = self.env['stock.request'].browse( + values['stock_request_id']).analytic_account_id.id + res.update(analytic_account_id=analytic_account_id) return res diff --git a/stock_request_analytic/models/stock_request.py b/stock_request_analytic/models/stock_request.py index f00888515..a18b9be82 100644 --- a/stock_request_analytic/models/stock_request.py +++ b/stock_request_analytic/models/stock_request.py @@ -13,9 +13,8 @@ class StockRequest(models.Model): @api.constrains('analytic_account_id') def _check_analytic_company_constrains(self): - if any(request.company_id and - request.analytic_account_id.company_id != - request.company_id for request in self): + if any(r.company_id and r.analytic_account_id and + r.analytic_account_id.company_id != r.company_id for r in self): raise ValidationError( _('You cannot link a analytic account ' 'to a stock request that belongs to ' diff --git a/stock_request_analytic/models/stock_request_order.py b/stock_request_analytic/models/stock_request_order.py index ac2fa75f8..c66068f57 100644 --- a/stock_request_analytic/models/stock_request_order.py +++ b/stock_request_analytic/models/stock_request_order.py @@ -7,23 +7,23 @@ from odoo import api, fields, models class StockRequestOrder(models.Model): _inherit = 'stock.request.order' - analytic_count = fields.Integer(string='analytic count', - compute='_compute_analytic_ids', - readonly=True) + analytic_count = fields.Integer( + compute='_compute_analytic_ids', + readonly=True, + ) analytic_account_ids = fields.One2many( - 'account.analytic.account', + comodel_name='account.analytic.account', compute='_compute_analytic_ids', string='Analytic Accounts', - readonly=True, copy=False) + readonly=True, + ) @api.depends('stock_request_ids') def _compute_analytic_ids(self): for req in self.sudo(): - req.analytic_ids = req.stock_request_ids.mapped( - 'analytic_account_id') req.analytic_account_ids = req.stock_request_ids.mapped( 'analytic_account_id') - req.analytic_count = len(req.analytic_ids) + req.analytic_count = len(req.analytic_account_ids) @api.multi def action_view_analytic(self): diff --git a/stock_request_analytic/views/stock_request_order_views.xml b/stock_request_analytic/views/stock_request_order_views.xml index 056cd0678..ae7f84da5 100644 --- a/stock_request_analytic/views/stock_request_order_views.xml +++ b/stock_request_analytic/views/stock_request_order_views.xml @@ -4,7 +4,7 @@ - stock.request.order.form + stock.request.order.form - stock_request_analytic stock.request.order @@ -13,14 +13,14 @@ - + diff --git a/stock_request_analytic/views/stock_request_views.xml b/stock_request_analytic/views/stock_request_views.xml index 100bd4749..156c9d07c 100644 --- a/stock_request_analytic/views/stock_request_views.xml +++ b/stock_request_analytic/views/stock_request_views.xml @@ -9,7 +9,7 @@ - +