[10.0][MIG] stock_cycle_count

This commit is contained in:
lreficent
2017-08-24 10:47:04 +02:00
committed by Mateu Griful
parent 1cd216016e
commit 4b951bf8bd
20 changed files with 130 additions and 127 deletions

View File

@@ -37,9 +37,9 @@ Recommendations
It is highly recommended to use this module in conjunction with:
* `stock_inventory_verification_request`: Adds the capability to request Slot
* ``stock_inventory_verification_request``: Adds the capability to request Slot
Verifications.
* `stock_inventory_lockdown`: Lock down locations during inventories.
* ``stock_inventory_lockdown``: Lock down locations during inventories.
Configuration
=============
@@ -72,7 +72,7 @@ is described below.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/153/9.0
:target: https://runbot.odoo-community.org/runbot/153/10.0
Bug Tracker
@@ -95,7 +95,6 @@ Contributors
* Lois Rilo <lois.rilo@eficent.com>
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
Maintainer
----------

View File

@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2016 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).
from . import models

View File

@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
# Copyright 2017-18 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).
{
"name": "Stock Cycle Count",
"summary": "Adds the capability to schedule cycle counts in a "
"warehouse through different rules defined by the user.",
"version": "10.0.1.0.0",
"author": "Eficent, "
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"category": "Warehouse Management",
"depends": [
"stock",
"mail",
"stock_inventory_discrepancy",
"stock_inventory_exclude_sublocation",
],
"external_dependencies": {
"python": ["numpy"],
},
"data": [
"views/stock_cycle_count_view.xml",
"views/stock_cycle_count_rule_view.xml",
"views/stock_warehouse_view.xml",
"views/stock_inventory_view.xml",
"views/stock_location_view.xml",
"data/cycle_count_sequence.xml",
"data/cycle_count_ir_cron.xml",
"reports/stock_location_accuracy_report.xml",
"reports/stock_cycle_count_report.xml",
"security/ir.model.access.csv",
],
"license": "AGPL-3",
"installable": True,
"application": False,
}

View File

@@ -1,36 +0,0 @@
# -*- 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).
{
"name": "Stock Cycle Count",
"summary": "Adds the capability to schedule cycle counts in a "
"warehouse through different rules defined by the user",
"version": "9.0.1.2.0",
"author": "Eficent, "
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"category": "Warehouse Management",
"depends": ["stock",
"mail",
"stock_inventory_discrepancy",
"stock_inventory_exclude_sublocation"],
"external_dependencies": {
"python": ['numpy'],
},
"data": [
'views/stock_cycle_count_view.xml',
'views/stock_cycle_count_rule_view.xml',
'views/stock_warehouse_view.xml',
'views/stock_inventory_view.xml',
'views/stock_location_view.xml',
'data/cycle_count_sequence.xml',
'data/cycle_count_ir_cron.xml',
'reports/stock_location_accuracy_report.xml',
'reports/stock_cycle_count_report.xml',
'security/ir.model.access.csv',
],
"license": "AGPL-3",
'installable': True,
'application': False,
}

View File

@@ -2,19 +2,19 @@
<!-- Copyright 2017 Eficent Business and IT Consulting Services S.L.
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<openerp>
<data noupdate="1">
<record forcecreate="True"
id="ir_cron_compute_cycle_count_action" model="ir.cron">
<field name="name">Cycle Count Planner Computation</field>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
<field name="model" eval="'stock.warehouse'"/>
<field name="function" eval="'cron_cycle_count'"/>
<field name="args" eval="'()'" />
</record>
</data>
</openerp>
<odoo noupdate="1">
<record forcecreate="True"
id="ir_cron_compute_cycle_count_action" model="ir.cron">
<field name="name">Cycle Count Planner Computation</field>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
<field name="model" eval="'stock.warehouse'"/>
<field name="function" eval="'cron_cycle_count'"/>
<field name="args" eval="'()'" />
</record>
</odoo>

View File

@@ -2,8 +2,7 @@
<!-- Copyright 2017 Eficent Business and IT Consulting Services S.L.
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<data noupdate="1">
<odoo noupdate="1">
<record id="seq_cycle_count" model="ir.sequence">
<field name="name">Cycle Count</field>
@@ -13,5 +12,4 @@
<field name="company_id" eval="False"/>
</record>
</data>
</odoo>

View File

@@ -1,6 +1,4 @@
# -*- 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).
from . import stock_cycle_count

View File

@@ -3,8 +3,8 @@
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openerp import api, fields, models, _
from openerp.exceptions import UserError
from odoo import api, fields, models, _
from odoo.exceptions import UserError
class StockCycleCount(models.Model):
@@ -12,9 +12,10 @@ class StockCycleCount(models.Model):
_description = "Stock Cycle Counts"
_inherit = 'mail.thread'
@api.one
@api.multi
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):
@@ -52,14 +53,14 @@ class StockCycleCount(models.Model):
inverse_name='cycle_count_id',
string='Inventory Adjustment',
track_visibility='onchange')
inventory_adj_count = fields.Integer(compute=_count_inventory_adj)
inventory_adj_count = fields.Integer(compute='_count_inventory_adj')
company_id = fields.Many2one(
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':
if any([s != 'draft' for s in self.mapped('state')]):
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:
data = rec._prepare_inventory_adjustment()
self.env['stock.inventory'].create(data)
self.write({'state': 'open'})
return True
@api.multi
@@ -86,11 +88,9 @@ class StockCycleCount(models.Model):
action = self.env.ref('stock.action_inventory_form')
result = action.read()[0]
result['context'] = {}
adjustment_ids = sum([cycle_count.stock_adjustment_ids.ids
for cycle_count in self], [])
adjustment_ids = self.mapped('stock_adjustment_ids').ids
if len(adjustment_ids) > 1:
result['domain'] = \
"[('id','in',[" + ','.join(map(str, adjustment_ids)) + "])]"
result['domain'] = [('id', 'in', adjustment_ids)]
elif len(adjustment_ids) == 1:
res = self.env.ref('stock.view_inventory_form', False)
result['views'] = [(res and res.id or False, 'form')]

View File

@@ -3,9 +3,9 @@
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openerp import api, fields, models, _
from openerp.exceptions import UserError
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
from odoo import api, fields, models, _
from odoo.exceptions import UserError
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
from datetime import timedelta, datetime
@@ -83,7 +83,7 @@ class StockCycleCountRule(models.Model):
"""Get the warehouses for the selected locations."""
wh_ids = []
for loc in self.location_ids:
wh_ids.append(loc.get_warehouse(loc))
wh_ids.append(loc.get_warehouse().id)
wh_ids = list(set(wh_ids))
self.warehouse_ids = self.env['stock.warehouse'].browse(wh_ids)
@@ -92,7 +92,7 @@ class StockCycleCountRule(models.Model):
string='Type of rule',
required=True)
rule_description = fields.Char(string='Rule Description',
compute=_get_rule_description)
compute='_get_rule_description')
active = fields.Boolean(string='Active', default=True)
periodic_qty_per_period = fields.Integer(string='Counts per period',
default=1)
@@ -101,7 +101,7 @@ class StockCycleCountRule(models.Model):
string='Turnover Inventory Value Threshold')
currency_id = fields.Many2one(comodel_name='res.currency',
string='Currency',
compute=_compute_currency)
compute='_compute_currency')
accuracy_threshold = fields.Float(string='Minimum Accuracy Threshold',
digits=(3, 2))
apply_in = fields.Selection(
@@ -175,7 +175,7 @@ class StockCycleCountRule(models.Model):
@api.model
def _compute_turnover(self, move):
price = move.get_price_unit(move)
price = move.get_price_unit()
turnover = move.product_uom_qty * price
return turnover

View File

@@ -3,8 +3,8 @@
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openerp import api, fields, models, _
from openerp.exceptions import UserError
from odoo import api, fields, models, _
from odoo.exceptions import UserError
PERCENT = 100.0
@@ -29,9 +29,9 @@ class StockInventory(models.Model):
cycle_count_id = fields.Many2one(
comodel_name='stock.cycle.count', string='Stock Cycle Count',
ondelete='cascade', readonly=True)
ondelete='restrict', readonly=True)
inventory_accuracy = fields.Float(
string='Accuracy', compute=_compute_inventory_accuracy,
string='Accuracy', compute='_compute_inventory_accuracy',
digits=(3, 2), store=True, group_operator="avg")
@api.multi

View File

@@ -5,8 +5,8 @@
import logging
from openerp import api, fields, models, tools
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
from odoo import api, fields, models, tools
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
from datetime import datetime
_logger = logging.getLogger(__name__)
@@ -26,8 +26,7 @@ class StockLocation(models.Model):
('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)
wh = self.get_warehouse()
if len(history) > wh.counts_for_accuracy_qty:
self.loc_accuracy = mean(history[:wh.counts_for_accuracy_qty].
mapped('inventory_accuracy'))
@@ -47,9 +46,9 @@ class StockLocation(models.Model):
qty_variance_inventory_threshold = fields.Float('Acceptable Inventory '
'Quantity Variance '
'Threshold')
loc_accuracy = fields.Float(string='Inventory Accuracy',
compute=_compute_loc_accuracy,
digits=(3, 2))
loc_accuracy = fields.Float(
string='Inventory Accuracy', compute='_compute_loc_accuracy',
digits=(3, 2))
@api.model
def _get_zero_confirmation_domain(self):
@@ -59,8 +58,7 @@ class StockLocation(models.Model):
@api.one
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)
wh = self.get_warehouse()
rule_model = self.env['stock.cycle.count.rule']
zero_rule = rule_model.search([
('rule_type', '=', 'zero'),
@@ -73,9 +71,8 @@ class StockLocation(models.Model):
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 = self.get_warehouse().id
date_horizon = self.get_warehouse().get_horizon_date()[0].strftime(
DEFAULT_SERVER_DATETIME_FORMAT)
counts_planned = self.env['stock.cycle.count'].search([
('date_deadline', '<', date_horizon), ('state', '=', 'draft'),

View File

@@ -3,7 +3,7 @@
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openerp import api, models
from odoo import api, models
class StockMove(models.Model):

View File

@@ -3,9 +3,12 @@
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openerp import api, fields, models
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
from odoo import api, fields, models
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
from datetime import datetime, timedelta
import logging
_logger = logging.getLogger(__name__)
class StockWarehouse(models.Model):
@@ -13,8 +16,7 @@ class StockWarehouse(models.Model):
cycle_count_rule_ids = fields.Many2many(
comodel_name='stock.cycle.count.rule',
relation='warehouse_cycle_count_'
'rule_rel',
relation='warehouse_cycle_count_rule_rel',
column1='warehouse_id',
column2='rule_id',
string='Cycle Count Rules')
@@ -113,6 +115,13 @@ class StockWarehouse(models.Model):
@api.model
def cron_cycle_count(self):
whs = self.search([])
whs.action_compute_cycle_count_rules()
_logger.info("stock_cycle_count cron job started.")
try:
whs = self.search([])
whs.action_compute_cycle_count_rules()
except:
_logger.info(
"An error raised while running stock_cycle_count cron job.")
raise
_logger.info("stock_cycle_count cron job ended.")
return True

View File

@@ -3,7 +3,7 @@
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openerp import api, models
from odoo import api, models
class LocationAccuracyReport(models.AbstractModel):

View File

@@ -1,6 +1,4 @@
# -*- 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).
from . import test_stock_cycle_count

View File

@@ -2,9 +2,9 @@
# 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).
from openerp.tests import common
from openerp.exceptions import ValidationError
from openerp.exceptions import AccessError
from odoo.tests import common
from odoo.exceptions import ValidationError
from odoo.exceptions import AccessError
from datetime import datetime, timedelta

View File

@@ -48,7 +48,7 @@
</div>
</group>
</group>
<group name="applied_in" string="Applied in:">
<group name="applied_in" string="Applied in:" col="4">
<p colspan="4">You can apply the cycle count rules in complete
warehouses or specific zones. A zone it is
understood as a location and all its children.</p>
@@ -57,7 +57,9 @@
"Exclude from Cycle Count".</p>
<field name="apply_in"/>
<field name="warehouse_ids" widget="many2many_tags"/>
<field name="location_ids"
<label for="location_ids"
attrs="{'invisible': [('apply_in', '!=', 'location')]}"/>
<field name="location_ids" colspan="3" nolabel="1"
attrs="{'invisible': [('apply_in', '!=', 'location')]}"/>
</group>

View File

@@ -135,7 +135,7 @@
<field name="type">ir.actions.server</field>
<field name="model_id" ref="model_stock_cycle_count" />
<field name="state">code</field>
<field name="code">self.action_create_inventory_adjustment(cr, uid, context.get('active_ids', []), context=context)</field>
<field name="code">records.action_create_inventory_adjustment()</field>
</record>
<record model="ir.values" id="action_cycle_count_confirm">

View File

@@ -15,14 +15,16 @@
context="{'location_id': active_ids}"
type="object"/>
</xpath>
<field name="active" position="after">
<field name="zero_confirmation_disabled"/>
<field name="cycle_count_disabled"/>
<label for="loc_accuracy"/>
<div>
<field name="loc_accuracy" class="oe_inline"/> %
</div>
</field>
<group name="localization" position="after">
<group name="cycle_count" string="Cycle Count">
<field name="zero_confirmation_disabled"/>
<field name="cycle_count_disabled"/>
<label for="loc_accuracy"/>
<div>
<field name="loc_accuracy" class="oe_inline"/> %
</div>
</group>
</group>
</field>
</record>

View File

@@ -30,7 +30,7 @@
<field name="type">ir.actions.server</field>
<field name="model_id" ref="model_stock_warehouse" />
<field name="state">code</field>
<field name="code">self.action_compute_cycle_count_rules(cr, uid, context.get('active_ids', []), context=context)</field>
<field name="code">records.action_compute_cycle_count_rules()</field>
</record>
<record model="ir.values" id="action_warehouse_execute_cycle_count">