mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
Merge pull request #458 from gurneyalex/9.0-fix-lint
[FIX][9.0] pylint warning and errors
This commit is contained in:
@@ -13,11 +13,11 @@ Usage
|
||||
=====
|
||||
|
||||
* The stock manager can check the journal items by accessing to 'Inventory >
|
||||
Reports > Stock moves'.
|
||||
Reports > Stock moves'.
|
||||
|
||||
* A user belonging to the group 'Accounting & Finance/Adviser' can review the
|
||||
details of a move that is associated to a journal item through
|
||||
'Invoicing > Adviser > Journal Entries (or Journal items)'.
|
||||
details of a move that is associated to a journal item through
|
||||
'Invoicing > Adviser > Journal Entries (or Journal items)'.
|
||||
|
||||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||
:alt: Try me on Runbot
|
||||
|
||||
@@ -12,9 +12,10 @@ class StockCycleCount(models.Model):
|
||||
_description = "Stock Cycle Counts"
|
||||
_inherit = 'mail.thread'
|
||||
|
||||
@api.one
|
||||
@api.depends('stock_adjustment_ids')
|
||||
def _count_inventory_adj(self):
|
||||
self.inventory_adj_count = len(self.stock_adjustment_ids)
|
||||
for rec in self:
|
||||
rec.inventory_adj_count = len(rec.stock_adjustment_ids)
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
@@ -57,9 +58,9 @@ class StockCycleCount(models.Model):
|
||||
comodel_name='res.company', string='Company', required=True,
|
||||
default=_company_get, readonly=True)
|
||||
|
||||
@api.one
|
||||
@api.multi
|
||||
def do_cancel(self):
|
||||
self.state = 'cancelled'
|
||||
self.write({'state': 'cancelled'})
|
||||
|
||||
@api.model
|
||||
def _prepare_inventory_adjustment(self):
|
||||
@@ -70,15 +71,16 @@ class StockCycleCount(models.Model):
|
||||
'exclude_sublocation': True
|
||||
}
|
||||
|
||||
@api.one
|
||||
@api.multi
|
||||
def action_create_inventory_adjustment(self):
|
||||
if self.state != 'draft':
|
||||
raise UserError(_(
|
||||
"You can only confirm cycle counts in state 'Planned'."
|
||||
))
|
||||
data = self._prepare_inventory_adjustment()
|
||||
self.env['stock.inventory'].create(data)
|
||||
self.state = 'open'
|
||||
for rec in self:
|
||||
if rec.state != 'draft':
|
||||
raise UserError(_(
|
||||
"You can only confirm cycle counts in state 'Planned'."
|
||||
))
|
||||
data = rec._prepare_inventory_adjustment()
|
||||
rec.env['stock.inventory'].create(data)
|
||||
rec.state = 'open'
|
||||
return True
|
||||
|
||||
@api.multi
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# coding: utf-8
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# (http://www.eficent.com)
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
@@ -13,9 +13,10 @@ class StockCycleCountRule(models.Model):
|
||||
_name = 'stock.cycle.count.rule'
|
||||
_description = "Stock Cycle Counts Rules"
|
||||
|
||||
@api.one
|
||||
@api.multi
|
||||
def _compute_currency(self):
|
||||
self.currency_id = self.env.user.company_id.currency_id
|
||||
for rec in self:
|
||||
rec.currency_id = self.env.user.company_id.currency_id
|
||||
|
||||
@api.model
|
||||
def _selection_rule_types(self):
|
||||
@@ -25,23 +26,23 @@ class StockCycleCountRule(models.Model):
|
||||
('accuracy', _('Minimum Accuracy')),
|
||||
('zero', _('Zero Confirmation'))]
|
||||
|
||||
@api.one
|
||||
@api.constrains('rule_type', 'warehouse_ids')
|
||||
def _check_zero_rule(self):
|
||||
if self.rule_type == 'zero' and len(self.warehouse_ids) > 1:
|
||||
raise UserError(
|
||||
_('Zero confirmation rules can only have one warehouse '
|
||||
'assigned.')
|
||||
)
|
||||
if self.rule_type == 'zero':
|
||||
zero_rule = self.search([
|
||||
('rule_type', '=', 'zero'),
|
||||
('warehouse_ids', '=', self.warehouse_ids.id)])
|
||||
if len(zero_rule) > 1:
|
||||
for rec in self:
|
||||
if rec.rule_type == 'zero' and len(rec.warehouse_ids) > 1:
|
||||
raise UserError(
|
||||
_('You can only have one zero confirmation rule per '
|
||||
'warehouse.')
|
||||
_('Zero confirmation rules can only have one warehouse '
|
||||
'assigned.')
|
||||
)
|
||||
if rec.rule_type == 'zero':
|
||||
zero_rule = self.search([
|
||||
('rule_type', '=', 'zero'),
|
||||
('warehouse_ids', '=', rec.warehouse_ids.id)])
|
||||
if len(zero_rule) > 1:
|
||||
err = _(
|
||||
'Warehouses can only have one zero-confirmation rule.'
|
||||
)
|
||||
raise UserError(err)
|
||||
|
||||
@api.onchange('rule_type')
|
||||
def _get_rule_description(self):
|
||||
|
||||
@@ -20,19 +20,26 @@ except (ImportError, IOError) as err:
|
||||
class StockLocation(models.Model):
|
||||
_inherit = 'stock.location'
|
||||
|
||||
@api.one
|
||||
@api.multi
|
||||
def _compute_loc_accuracy(self):
|
||||
history = self.env['stock.inventory'].search([
|
||||
('location_id', '=', self.id), ('state', '=', 'done')])
|
||||
history = history.sorted(key=lambda r: r.write_date, reverse=True)
|
||||
if history:
|
||||
wh_id = self.get_warehouse(self)
|
||||
wh = self.env['stock.warehouse'].browse(wh_id)
|
||||
if len(history) > wh.counts_for_accuracy_qty:
|
||||
self.loc_accuracy = mean(history[:wh.counts_for_accuracy_qty].
|
||||
mapped('inventory_accuracy'))
|
||||
else:
|
||||
self.loc_accuracy = mean(history.mapped('inventory_accuracy'))
|
||||
for rec in self:
|
||||
history = self.env['stock.inventory'].search(
|
||||
[('location_id', '=', rec.id),
|
||||
('state', '=', 'done'),
|
||||
],
|
||||
order='write_date DESC'
|
||||
)
|
||||
if history:
|
||||
wh_id = rec.get_warehouse(rec)
|
||||
wh = self.env['stock.warehouse'].browse(wh_id)
|
||||
if len(history) > wh.counts_for_accuracy_qty:
|
||||
rec.loc_accuracy = mean(
|
||||
history[:wh.counts_for_accuracy_qty].
|
||||
mapped('inventory_accuracy'))
|
||||
else:
|
||||
rec.loc_accuracy = mean(
|
||||
history.mapped('inventory_accuracy')
|
||||
)
|
||||
|
||||
zero_confirmation_disabled = fields.Boolean(
|
||||
string='Disable Zero Confirmations',
|
||||
@@ -56,26 +63,27 @@ class StockLocation(models.Model):
|
||||
domain = [('location_id', '=', self.id)]
|
||||
return domain
|
||||
|
||||
@api.one
|
||||
@api.multi
|
||||
def check_zero_confirmation(self):
|
||||
if not self.zero_confirmation_disabled:
|
||||
wh_id = self.get_warehouse(self)
|
||||
wh = self.env['stock.warehouse'].browse(wh_id)
|
||||
rule_model = self.env['stock.cycle.count.rule']
|
||||
zero_rule = rule_model.search([
|
||||
('rule_type', '=', 'zero'),
|
||||
('warehouse_ids', '=', wh.id)])
|
||||
if zero_rule:
|
||||
quants = self.env['stock.quant'].search(
|
||||
self._get_zero_confirmation_domain())
|
||||
if not quants:
|
||||
self.create_zero_confirmation_cycle_count()
|
||||
rule_model = self.env['stock.cycle.count.rule']
|
||||
for rec in self:
|
||||
if not rec.zero_confirmation_disabled:
|
||||
wh_id = rec.get_warehouse(rec)
|
||||
wh = self.env['stock.warehouse'].browse(wh_id)
|
||||
zero_rule = rule_model.search([
|
||||
('rule_type', '=', 'zero'),
|
||||
('warehouse_ids', '=', wh.id)])
|
||||
if zero_rule:
|
||||
quants = self.env['stock.quant'].search(
|
||||
rec._get_zero_confirmation_domain())
|
||||
if not quants:
|
||||
rec.create_zero_confirmation_cycle_count()
|
||||
|
||||
def create_zero_confirmation_cycle_count(self):
|
||||
date = datetime.today().strftime(DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
wh_id = self.get_warehouse(self)
|
||||
date_horizon = self.env['stock.warehouse'].browse(
|
||||
wh_id).get_horizon_date()[0].strftime(
|
||||
wh_id).get_horizon_date().strftime(
|
||||
DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
counts_planned = self.env['stock.cycle.count'].search([
|
||||
('date_deadline', '<', date_horizon), ('state', '=', 'draft'),
|
||||
|
||||
@@ -28,8 +28,9 @@ class StockWarehouse(models.Model):
|
||||
help='Number of latest inventories used to calculate location '
|
||||
'accuracy')
|
||||
|
||||
@api.one
|
||||
@api.multi
|
||||
def get_horizon_date(self):
|
||||
self.ensure_one()
|
||||
date = datetime.today()
|
||||
delta = timedelta(self.cycle_count_planning_horizon)
|
||||
date_horizon = date + delta
|
||||
@@ -62,11 +63,15 @@ class StockWarehouse(models.Model):
|
||||
('rule_type', '!=', 'zero'), ('warehouse_ids', '=', self.id)])
|
||||
return rules
|
||||
|
||||
@api.one
|
||||
@api.multi
|
||||
def action_compute_cycle_count_rules(self):
|
||||
''' Apply the rule in all the sublocations of a given warehouse(s) and
|
||||
returns a list with required dates for the cycle count of each
|
||||
location '''
|
||||
for rec in self:
|
||||
rec._do_compute_cycle_count_rules()
|
||||
|
||||
def _do_compute_cycle_count_rules(self):
|
||||
proposed_cycle_counts = []
|
||||
rules = self._cycle_count_rules_to_compute()
|
||||
for rule in rules:
|
||||
|
||||
@@ -150,12 +150,12 @@ class DemandEstimateWizard(models.TransientModel):
|
||||
comodel_name="product.product",
|
||||
string="Products")
|
||||
|
||||
@api.one
|
||||
@api.constrains('date_start', 'date_end')
|
||||
def _check_start_end_dates(self):
|
||||
if self.date_start > self.date_end:
|
||||
raise ValidationError(_(
|
||||
'The start date cannot be later than the end date.'))
|
||||
for rec in self:
|
||||
if rec.date_start > rec.date_end:
|
||||
raise ValidationError(_(
|
||||
'The start date cannot be later than the end date.'))
|
||||
|
||||
@api.multi
|
||||
def _prepare_demand_estimate_sheet(self):
|
||||
|
||||
@@ -49,4 +49,4 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||
mission is to support the collaborative development of Odoo features and
|
||||
promote its widespread use.
|
||||
|
||||
To contribute to this module, please visit https://odoo-community.org.
|
||||
To contribute to this module, please visit https://odoo-community.org.
|
||||
|
||||
@@ -17,13 +17,14 @@ class StockInventory(models.Model):
|
||||
('pending', 'Pending to Approve'),
|
||||
('done', 'Validated')]
|
||||
|
||||
@api.one
|
||||
@api.depends('line_ids.product_qty', 'line_ids.theoretical_qty')
|
||||
def _compute_over_discrepancy_line_count(self):
|
||||
lines = self.line_ids
|
||||
self.over_discrepancy_line_count = sum(
|
||||
d.discrepancy_percent > d.discrepancy_threshold
|
||||
for d in lines)
|
||||
for rec in self:
|
||||
lines = rec.line_ids.filtered(
|
||||
lambda line:
|
||||
line.discrepancy_percent > line.discrepancy_threshold
|
||||
)
|
||||
rec.over_discrepancy_line_count = len(lines)
|
||||
|
||||
state = fields.Selection(
|
||||
selection=INVENTORY_STATE_SELECTION,
|
||||
@@ -57,15 +58,16 @@ class StockInventory(models.Model):
|
||||
'this action.')
|
||||
)
|
||||
|
||||
@api.one
|
||||
@api.multi
|
||||
def action_done(self):
|
||||
if self.over_discrepancy_line_count and self.line_ids.filtered(
|
||||
lambda t: t.discrepancy_threshold > 0.0):
|
||||
if self.env.context.get('normal_view', False):
|
||||
self.action_over_discrepancies()
|
||||
return True
|
||||
else:
|
||||
self._check_group_inventory_validation_always()
|
||||
for rec in self:
|
||||
if rec.over_discrepancy_line_count and rec.line_ids.filtered(
|
||||
lambda t: t.discrepancy_threshold > 0.0):
|
||||
if self.env.context.get('normal_view', False):
|
||||
rec.action_over_discrepancies()
|
||||
return True
|
||||
else:
|
||||
rec._check_group_inventory_validation_always()
|
||||
return super(StockInventory, self).action_done()
|
||||
|
||||
@api.multi
|
||||
|
||||
@@ -9,26 +9,29 @@ from openerp import api, fields, models
|
||||
class StockInventoryLine(models.Model):
|
||||
_inherit = 'stock.inventory.line'
|
||||
|
||||
@api.one
|
||||
@api.depends('product_qty', 'theoretical_qty')
|
||||
def _compute_discrepancy(self):
|
||||
self.discrepancy_qty = self.product_qty - self.theoretical_qty
|
||||
if self.theoretical_qty:
|
||||
self.discrepancy_percent = 100 * abs(
|
||||
(self.product_qty - self.theoretical_qty) /
|
||||
self.theoretical_qty)
|
||||
elif not self.theoretical_qty and self.product_qty:
|
||||
self.discrepancy_percent = 100.0
|
||||
for rec in self:
|
||||
rec.discrepancy_qty = rec.product_qty - rec.theoretical_qty
|
||||
if rec.theoretical_qty:
|
||||
rec.discrepancy_percent = 100 * abs(
|
||||
(rec.product_qty - rec.theoretical_qty) /
|
||||
rec.theoretical_qty)
|
||||
elif not rec.theoretical_qty and rec.product_qty:
|
||||
rec.discrepancy_percent = 100.0
|
||||
|
||||
@api.one
|
||||
@api.multi
|
||||
def _get_discrepancy_threshold(self):
|
||||
wh_id = self.location_id.get_warehouse(self.location_id)
|
||||
wh = self.env['stock.warehouse'].browse(wh_id)
|
||||
if self.location_id.discrepancy_threshold > 0.0:
|
||||
self.discrepancy_threshold = self.location_id.discrepancy_threshold
|
||||
elif wh.discrepancy_threshold > 0.0:
|
||||
self.discrepancy_threshold = wh.discrepancy_threshold
|
||||
else:
|
||||
self.discrepancy_threshold = False
|
||||
for rec in self:
|
||||
wh_id = rec.location_id.get_warehouse(rec.location_id)
|
||||
wh = self.env['stock.warehouse'].browse(wh_id)
|
||||
if rec.location_id.discrepancy_threshold > 0.0:
|
||||
rec.discrepancy_threshold = \
|
||||
rec.location_id.discrepancy_threshold
|
||||
elif wh.discrepancy_threshold > 0.0:
|
||||
rec.discrepancy_threshold = wh.discrepancy_threshold
|
||||
else:
|
||||
rec.discrepancy_threshold = False
|
||||
|
||||
discrepancy_qty = fields.Float(
|
||||
string='Discrepancy',
|
||||
|
||||
@@ -35,6 +35,9 @@ class StockInventory(models.Model):
|
||||
domain += ' and package_id = %s'
|
||||
args += (inventory.package_id.id,)
|
||||
|
||||
# disable error about SQL injection as the code here is generating
|
||||
# a vulnerability
|
||||
# pylint: disable = E8103
|
||||
self.env.cr.execute('''
|
||||
SELECT product_id, sum(qty) as product_qty, location_id, lot_id
|
||||
as prod_lot_id, package_id, owner_id as partner_id
|
||||
|
||||
@@ -16,13 +16,15 @@ class SlotVerificationRequest(models.Model):
|
||||
'stock.slot.verification.request') or ''
|
||||
return super(SlotVerificationRequest, self).create(vals)
|
||||
|
||||
@api.one
|
||||
@api.depends('involved_move_ids')
|
||||
def _count_involved_moves(self):
|
||||
self.involved_move_count = len(self.involved_move_ids)
|
||||
for rec in self:
|
||||
rec.involved_move_count = len(rec.involved_move_ids)
|
||||
|
||||
@api.one
|
||||
@api.depends('involved_inv_line_ids')
|
||||
def _count_involved_inv_lines(self):
|
||||
self.involved_inv_line_count = len(self.involved_inv_line_ids)
|
||||
for rec in self:
|
||||
rec.involved_inv_line_count = len(rec.involved_inv_line_ids)
|
||||
|
||||
name = fields.Char(string='Name', readonly=True)
|
||||
inventory_id = fields.Many2one(comodel_name='stock.inventory',
|
||||
@@ -60,20 +62,17 @@ class SlotVerificationRequest(models.Model):
|
||||
string='Involved Inventory Lines')
|
||||
involved_inv_line_count = fields.Integer(compute=_count_involved_inv_lines)
|
||||
|
||||
@api.model
|
||||
def _get_involved_moves_domain(self):
|
||||
domain = [('product_id', '=', self.product_id.id), '|',
|
||||
('location_id', '=', self.location_id.id),
|
||||
('location_dest_id', '=', self.location_id.id)]
|
||||
return domain
|
||||
|
||||
@api.model
|
||||
def _get_involved_lines_domain(self):
|
||||
domain = [('product_id', '=', self.product_id.id),
|
||||
('location_id', '=', self.location_id.id)]
|
||||
return domain
|
||||
|
||||
@api.model
|
||||
def _get_involved_lines_and_locations(self):
|
||||
involved_moves = self.env['stock.move'].search(
|
||||
self._get_involved_moves_domain())
|
||||
@@ -81,23 +80,24 @@ class SlotVerificationRequest(models.Model):
|
||||
self._get_involved_lines_domain())
|
||||
return involved_moves, involved_lines
|
||||
|
||||
@api.one
|
||||
@api.multi
|
||||
def action_confirm(self):
|
||||
self.state = 'open'
|
||||
involved_moves, involved_lines = \
|
||||
self._get_involved_lines_and_locations()
|
||||
self.involved_move_ids = involved_moves
|
||||
self.involved_inv_line_ids = involved_lines
|
||||
for rec in self:
|
||||
rec.state = 'open'
|
||||
involved_moves, involved_lines = \
|
||||
rec._get_involved_lines_and_locations()
|
||||
rec.involved_move_ids = involved_moves
|
||||
rec.involved_inv_line_ids = involved_lines
|
||||
return True
|
||||
|
||||
@api.one
|
||||
@api.multi
|
||||
def action_cancel(self):
|
||||
self.state = 'cancelled'
|
||||
self.write({'state': 'cancelled'})
|
||||
return True
|
||||
|
||||
@api.one
|
||||
@api.multi
|
||||
def action_solved(self):
|
||||
self.state = 'done'
|
||||
self.write({'state': 'done'})
|
||||
return True
|
||||
|
||||
@api.multi
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<record id="view_inventory_form" model="ir.ui.view">
|
||||
<field name="name">Inventory form view - SVR extension </field>
|
||||
<field name="model">stock.inventory</field>
|
||||
<field name="inherit_id" ref="stock.view_inventory_form"/>
|
||||
<field name="inherit_id" ref="stock_inventory_discrepancy.view_inventory_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//button[@name='action_done']"
|
||||
position="after">
|
||||
|
||||
@@ -52,4 +52,4 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||
mission is to support the collaborative development of Odoo features and
|
||||
promote its widespread use.
|
||||
|
||||
To contribute to this module, please visit https://odoo-community.org.
|
||||
To contribute to this module, please visit https://odoo-community.org.
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# coding: utf-8
|
||||
# Author: Florian da Costa
|
||||
# Copyright 2015 Akretion
|
||||
#
|
||||
|
||||
@@ -31,4 +31,4 @@
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
</odoo>
|
||||
|
||||
@@ -33,4 +33,4 @@
|
||||
<act_window name="Manual quants" res_model="assign.manual.quants"
|
||||
src_model="stock.move" view_mode="form" target="new"
|
||||
id="assign_manual_quants_action" />
|
||||
</odoo>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user