Port stock_usability to v10

This commit is contained in:
Alexis de Lattre
2016-11-21 17:51:10 +01:00
parent acfd2f18a7
commit ed1937d501
4 changed files with 70 additions and 150 deletions

View File

@@ -1,26 +1,9 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Procurement Usability module for Odoo
# Copyright (C) 2015 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# -*- coding: utf-8 -*-
# © 2015-2016 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import models, fields
from odoo import models, fields, api
from datetime import datetime
import logging
@@ -30,15 +13,14 @@ logger = logging.getLogger(__name__)
class ProcurementOrder(models.Model):
_inherit = 'procurement.order'
@api.model
def _procure_orderpoint_confirm(
self, cr, uid, use_new_cursor=False, company_id=False,
context=None):
self, use_new_cursor=False, company_id=False):
logger.info(
'procurement scheduler: START to create procurements from '
'orderpoints')
res = super(ProcurementOrder, self)._procure_orderpoint_confirm(
cr, uid, use_new_cursor=use_new_cursor, company_id=company_id,
context=context)
use_new_cursor=use_new_cursor, company_id=company_id)
logger.info(
'procurement scheduler: END creation of procurements from '
'orderpoints')
@@ -46,38 +28,36 @@ class ProcurementOrder(models.Model):
# Why is this code in stock_usability and not in procurement_usability ?
# For a very good reason
# The stock module inherits run_scheduler(). So, if we want to have the START and
# END log message and a good end date for procurement.scheduler.log
# the method below must be called first, so we must be "above" all
# modules that call run_scheduler()
# The stock module inherits run_scheduler(). So, if we want to have the
# START and END log message and a good end date
# for procurement.scheduler.log, the method below must be called first,
# so we must be "above" all modules that call run_scheduler()
@api.model
def run_scheduler(
self, cr, uid, use_new_cursor=False, company_id=False,
context=None):
self, use_new_cursor=False, company_id=False):
'''Inherit to add info logs'''
logger.info(
'START procurement scheduler '
'(company ID=%d, uid=%d, use_new_cursor=%s)',
company_id, uid, use_new_cursor)
company_id, self._uid, use_new_cursor)
start_datetime = datetime.now()
res = super(ProcurementOrder, self).run_scheduler(
cr, uid, use_new_cursor=use_new_cursor, company_id=company_id,
context=context)
use_new_cursor=use_new_cursor, company_id=company_id)
logger.info(
'END procurement scheduler '
'(company ID=%d, uid=%d, use_new_cursor=%s)',
company_id, uid, use_new_cursor)
company_id, self._uid, use_new_cursor)
try:
# I put it in a try/except, to be sure that, even if the user
# the execute the scheduler doesn't have create right on
# procurement.scheduler.log
self.pool['procurement.scheduler.log'].create(
cr, uid, {
'company_id': company_id,
'start_datetime': start_datetime,
}, context=context)
self.env['procurement.scheduler.log'].create({
'company_id': company_id,
'start_datetime': start_datetime,
})
# If I don't do an explicit cr.commit(), it doesn't create
# the procurement.scheduler.log... I don't know why
cr.commit()
self._cr.commit()
except:
logger.warning('Could not create procurement.scheduler.log')
return res

View File

@@ -1,22 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015-2016 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __openerp__.py
© 2015-2016 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<openerp>
<data>
<odoo>
<record id="procurement_group_form_view" model="ir.ui.view">
<field name="name">stock_usability.procurement.group.form</field>
<field name="model">procurement.group</field>
<field name="inherit_id" ref="procurement.procurement_group_form_view"/>
<field name="inherit_id" ref="stock.procurement_group_form_view_herited"/>
<field name="arch" type="xml">
<field name="move_type" position="after">
<field name="partner_id" readonly="True"/>
</field>
<xpath expr="//field[@name='move_type']/.." position="after">
<group name="picking" string="Pickings">
<field name="picking_ids" nolabel="1"/>
</group>
</xpath>
</field>
</record>
@@ -31,7 +34,7 @@
</group>
</xpath>
<field name="partner_dest_id" position="before">
<field name="orderpoint_id" readonly="True"/>
<field name="orderpoint_id" readonly="1"/>
</field>
</field>
</record>
@@ -59,5 +62,4 @@
action="procurement_scheduler_log_action"
parent="stock.menu_stock_sched" sequence="22"/>
</data>
</openerp>
</odoo>

View File

@@ -49,6 +49,10 @@ class StockLocationRoute(models.Model):
class StockWarehouseOrderpoint(models.Model):
_inherit = 'stock.warehouse.orderpoint'
# This SQL constraint blocks the use of the "active" field
# but I think it's not very useful to have such an "active" field
# on orderpoints ; when you think the order point is bad, you update
# the min/max values, you don't de-active it !
_sql_constraints = [(
'company_wh_location_product_unique',
'unique(company_id, warehouse_id, location_id, product_id)',
@@ -68,12 +72,13 @@ class StockMove(models.Model):
# availability = fields.Float(
# digits=dp.get_precision('Product Unit of Measure'))
def name_get(self, cr, uid, ids, context=None):
@api.multi
def name_get(self):
'''name_get of stock_move is important for the reservation of the
quants: so want to add the name of the customer and the expected date
in it'''
res = []
for line in self.browse(cr, uid, ids, context=context):
for line in self:
name = line.location_id.name + ' > ' + line.location_dest_id.name
if line.product_id.code:
name = line.product_id.code + ': ' + name
@@ -88,13 +93,6 @@ class StockMove(models.Model):
return res
class StockQuant(models.Model):
_inherit = 'stock.quant'
uom_id = fields.Many2one(
'product.uom', related='product_id.uom_id', readonly=True)
class StockIncoterms(models.Model):
_inherit = 'stock.incoterms'

View File

@@ -1,13 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2014-2016 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __openerp__.py
© 2014-2016 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<openerp>
<data>
<odoo>
<record id="view_picking_form" model="ir.ui.view">
@@ -18,8 +16,8 @@
<field name="backorder_id" position="attributes">
<attribute name="attrs">{}</attribute>
</field>
<field name="date_done" position="attributes">
<attribute name="groups"></attribute>
<field name="min_date" position="after">
<field name="date_done" states="done"/>
</field>
<!-- Maybe it's usefull to always display stock pack operations...
or maybe only for debugging... I haven't decided yet !
@@ -38,15 +36,15 @@
<group expand="0" position="inside">
<filter string="Partner" context="{'group_by': 'partner_id'}"/>
</group>
<filter string="Origin" position="replace"/>
<filter string="Expected Date" position="attributes">
<filter context="{'group_by':'origin'}" position="replace"/>
<filter context="{'group_by':'min_date'}" position="after">
<filter name="date_done" string="Date Done"
context="{'group_by': 'date_done:day'}"/>
</filter>
<filter context="{'group_by':'min_date'}" position="attributes">
<!-- group per day -->
<attribute name="context">"{'group_by': 'min_date:day'}"</attribute>
</filter>
<filter string="Expected Date" position="after">
<filter name="date_done" string="Date Done"
context="{'group_by':'date_done:day'}"/>
</filter>
</field>
</record>
@@ -98,11 +96,14 @@
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_form" />
<field name="arch" type="xml">
<!-- There are no button any more on that view...
so probably not a good idea to add one
<button name="force_assign" position="after">
<button type="object" name="do_unreserve" string="Unreserve"
groups="stock.group_stock_user"
states="confirmed,assigned"/>
</button>
-->
<group name="moved_quants_grp" position="after">
<notebook colspan="2">
<page string="Notes" name="notes">
@@ -128,6 +129,7 @@
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_picking_form" />
<field name="arch" type="xml">
<field name="group_id" position="replace"/> <!-- in stock, this field has invisible="1" re-add it below as visible -->
<group name="moved_quants_grp" position="after">
<notebook colspan="2">
<page string="Notes" name="notes">
@@ -148,6 +150,8 @@
</field>
</record>
<!-- This view has changed a lot ; most fields are invisible, so it's probably not used a lot -->
<!--
<record id="view_move_picking_tree" model="ir.ui.view">
<field name="name">stock_usability.src_location.in.picking.form</field>
<field name="model">stock.move</field>
@@ -163,21 +167,22 @@
</field>
</field>
</record>
-->
<record id="view_warehouse" model="ir.ui.view">
<field name="name">stock.usability.warehouse.form</field>
<field name="model">stock.warehouse</field>
<field name="inherit_id" ref="stock.view_warehouse" />
<field name="arch" type="xml">
<group string="Picking Types" position="after">
<xpath expr="//field[@name='out_type_id']/.." position="after">
<group name="routes" string="Routes">
<field name="route_ids" widget="many2many_tags"/>
<field name="route_ids" widget="many2many_tags"/>
<field name="crossdock_route_id"/>
<field name="reception_route_id"/>
<field name="delivery_route_id"/>
<field name="resupply_route_ids"/>
</group>
</group>
</xpath>
<field name="wh_input_stock_loc_id" position="before">
<field name="lot_stock_id" readonly="1" required="0"/>
<field name="view_location_id" groups="base.group_no_one"
@@ -191,36 +196,12 @@
<field name="model">stock.location</field>
<field name="inherit_id" ref="stock.view_location_search" />
<field name="arch" type="xml">
<field name="location_id" position="after">
<filter name="inactive" position="after">
<group string="Group By" name="groupby">
<filter name="usage" string="Location Type"
context="{'group_by': 'usage'}"/>
</group>
</field>
</field>
</record>
<record id="stock_location_path_action" model="ir.actions.act_window">
<field name="name">Push Rules</field>
<field name="res_model">stock.location.path</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem id="stock_location_path_menu" action="stock_location_path_action"
sequence="10" parent="stock.menu_stock_configuration"/>
<!-- Display total qty in Transfer wizard
Usefull because some delivery order from suppliers contains the "total number of items"
So the Odoo user can easily check that he doesn't make mistakes
in the quantities for his reception -->
<record id="view_stock_enter_transfer_details" model="ir.ui.view">
<field name="name">stock.usability.transfer_details.form</field>
<field name="model">stock.transfer_details</field>
<field name="inherit_id" ref="stock.view_stock_enter_transfer_details"/>
<field name="arch" type="xml">
<field name="quantity" position="attributes">
<attribute name="sum">Total</attribute>
</field>
</filter>
</field>
</record>
@@ -235,39 +216,10 @@ in the quantities for his reception -->
<field name="qty" position="attributes">
<attribute name="sum">Total Qty</attribute>
</field>
<field name="qty" position="after">
<field name="uom_id"/>
</field>
</field>
</record>
<record id="view_stock_quant_form" model="ir.ui.view">
<field name="name">stock.usability.quant.form</field>
<field name="model">stock.quant</field>
<field name="inherit_id" ref="stock.view_stock_quant_form"/>
<field name="arch" type="xml">
<field name="qty" position="replace">
<label for="qty"/>
<div>
<field name="qty" class="oe_inline"/>
<field name="uom_id" class="oe_inline"/>
</div>
</field>
</field>
</record>
<record id="view_move_tree_receipt_picking" model="ir.ui.view">
<field name="name">stock.usability.stock.move.tree2</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_tree_receipt_picking"/>
<field name="arch" type="xml">
<field name="date_expected" position="attributes">
<attribute name="invisible">0</attribute>
</field>
</field>
</record>
<!--
<record id="view_template_property_form" model="ir.ui.view">
<field name="name">stock.usability.product.template.form</field>
<field name="model">product.template</field>
@@ -278,24 +230,12 @@ in the quantities for his reception -->
</field>
</field>
</record>
-->
<!-- more detailed stock.move tree view when using the button from product form -->
<!-- TODO TEST
<record id="stock.act_product_stock_move_open" model="ir.actions.act_window">
<field name="view_id" ref="stock.view_move_tree"/>
</record>
</record> -->
<record id="procurement_group_form_view" model="ir.ui.view">
<field name="name">stock_usability.procurement.group.form</field>
<field name="model">procurement.group</field>
<field name="inherit_id" ref="procurement.procurement_group_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='move_type']/.." position="after">
<group name="picking" string="Pickings">
<field name="picking_ids" nolabel="1"/>
</group>
</xpath>
</field>
</record>
</data>
</openerp>
</odoo>