Add scheduler.procurement.log
Re-organize the code, so that each module xxx_usability only depend on xxx
This commit is contained in:
@@ -1,23 +1 @@
|
||||
# -*- 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from . import procurement
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
@@ -37,7 +37,9 @@ This module has been written by Alexis de Lattre from Akretion <alexis.delattre@
|
||||
""",
|
||||
'author': 'Akretion',
|
||||
'website': 'http://www.akretion.com',
|
||||
'depends': ['sale_stock'],
|
||||
'data': ['procurement_view.xml'],
|
||||
'depends': ['procurement'],
|
||||
'data': [
|
||||
'procurement_view.xml',
|
||||
],
|
||||
'installable': True,
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
# -*- 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp import models, fields
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ProcurementOrder(models.Model):
|
||||
_inherit = 'procurement.order'
|
||||
|
||||
def run_scheduler(
|
||||
self, cr, uid, use_new_cursor=False, company_id=False,
|
||||
context=None):
|
||||
'''Inherit to add info logs'''
|
||||
logger.info(
|
||||
'START procurement scheduler (company ID=%d, uid=%d)',
|
||||
company_id, uid)
|
||||
res = super(ProcurementOrder, self).run_scheduler(
|
||||
cr, uid, use_new_cursor=use_new_cursor, company_id=company_id,
|
||||
context=context)
|
||||
logger.info(
|
||||
'END procurement scheduler (company ID=%d, uid=%d)',
|
||||
company_id, uid)
|
||||
return res
|
||||
|
||||
|
||||
class ProcurementGroup(models.Model):
|
||||
_inherit = 'procurement.group'
|
||||
|
||||
sale_ids = fields.One2many(
|
||||
'sale.order', 'procurement_group_id', string='Sale Orders',
|
||||
readonly=True)
|
||||
picking_ids = fields.One2many(
|
||||
'stock.picking', 'group_id', string='Pickings', readonly=True)
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
Copyright (C) 2015 Akretion (http://www.akretion.com/)
|
||||
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
|
||||
-->
|
||||
@@ -9,43 +9,15 @@
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="view_procurement_form_stock_inherit" model="ir.ui.view">
|
||||
<field name="name">procurement_usability.procurement.order.form</field>
|
||||
<field name="model">procurement.order</field>
|
||||
<field name="inherit_id" ref="stock.view_procurement_form_stock_inherit"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="origin" position="after">
|
||||
<field name="sale_line_id" readonly="True"/> <!-- field defined in the sale module -->
|
||||
</field>
|
||||
<xpath expr="//field[@name='company_id']/.." position="after">
|
||||
<group name="move_ids" string="Stock Moves" colspan="4">
|
||||
<field name="move_ids" nolabel="1" readonly="True"/>
|
||||
</group>
|
||||
</xpath>
|
||||
<field name="partner_dest_id" position="before">
|
||||
<field name="orderpoint_id" readonly="True"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="procurement_group_form_view" model="ir.ui.view">
|
||||
<field name="name">procurement_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">
|
||||
<field name="move_type" position="after">
|
||||
<field name="partner_id" readonly="True"/>
|
||||
</field>
|
||||
<xpath expr="//field[@name='move_type']/.." position="after">
|
||||
<group name="procurements" string="Procurements">
|
||||
<field name="procurement_ids" nolabel="1"/>
|
||||
</group>
|
||||
<group name="sale" string="Sale Orders">
|
||||
<field name="sale_ids" nolabel="1"/>
|
||||
</group>
|
||||
<group name="picking" string="Pickings">
|
||||
<field name="picking_ids" nolabel="1"/>
|
||||
</group>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -40,3 +40,13 @@ class SaleOrderLine(models.Model):
|
||||
product_tmpl_id = fields.Many2one(
|
||||
'product.template', related='product_id.product_tmpl_id',
|
||||
string='Product Template', readonly=True)
|
||||
|
||||
|
||||
class ProcurementGroup(models.Model):
|
||||
_inherit = 'procurement.group'
|
||||
|
||||
sale_ids = fields.One2many(
|
||||
'sale.order', 'procurement_group_id', string='Sale Orders',
|
||||
readonly=True)
|
||||
picking_ids = fields.One2many(
|
||||
'stock.picking', 'group_id', string='Pickings', readonly=True)
|
||||
|
||||
@@ -34,5 +34,22 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="procurement_group_form_view" model="ir.ui.view">
|
||||
<field name="name">sale_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="sale" string="Sale Orders">
|
||||
<field name="sale_ids" nolabel="1"/>
|
||||
</group>
|
||||
<group name="picking" string="Pickings">
|
||||
<field name="picking_ids" nolabel="1"/>
|
||||
</group>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
@@ -64,5 +64,16 @@
|
||||
|
||||
<!-- TODO : handle date_confirm in search/graph views -->
|
||||
|
||||
<record id="procurement_form_view" model="ir.ui.view">
|
||||
<field name="name">procurement_usability.procurement.order.form</field>
|
||||
<field name="model">procurement.order</field>
|
||||
<field name="inherit_id" ref="procurement.procurement_form_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="origin" position="after">
|
||||
<field name="sale_line_id" readonly="True"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import stock
|
||||
from . import procurement
|
||||
|
||||
@@ -43,6 +43,10 @@ This module has been written by Alexis de Lattre from Akretion <alexis.delattre@
|
||||
'author': 'Akretion',
|
||||
'website': 'http://www.akretion.com',
|
||||
'depends': ['stock'],
|
||||
'data': ['stock_view.xml'],
|
||||
'data': [
|
||||
'stock_view.xml',
|
||||
'procurement_view.xml',
|
||||
'security/ir.model.access.csv',
|
||||
],
|
||||
'installable': True,
|
||||
}
|
||||
|
||||
93
stock_usability/procurement.py
Normal file
93
stock_usability/procurement.py
Normal file
@@ -0,0 +1,93 @@
|
||||
# -*- 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp import models, fields
|
||||
from datetime import datetime
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ProcurementOrder(models.Model):
|
||||
_inherit = 'procurement.order'
|
||||
|
||||
def _procure_orderpoint_confirm(
|
||||
self, cr, uid, use_new_cursor=False, company_id=False,
|
||||
context=None):
|
||||
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)
|
||||
logger.info(
|
||||
'procurement scheduler: END creation of procurements from '
|
||||
'orderpoints')
|
||||
return res
|
||||
|
||||
# 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()
|
||||
def run_scheduler(
|
||||
self, cr, uid, use_new_cursor=False, company_id=False,
|
||||
context=None):
|
||||
'''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)
|
||||
start_datetime = datetime.now()
|
||||
res = super(ProcurementOrder, self).run_scheduler(
|
||||
cr, uid, use_new_cursor=use_new_cursor, company_id=company_id,
|
||||
context=context)
|
||||
logger.info(
|
||||
'END procurement scheduler '
|
||||
'(company ID=%d, uid=%d, use_new_cursor=%s)',
|
||||
company_id, 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)
|
||||
# If I don't do an explicit cr.commit(), it doesn't create
|
||||
# the procurement.scheduler.log... I don't know why
|
||||
cr.commit()
|
||||
except:
|
||||
logger.warning('Could not create procurement.scheduler.log')
|
||||
return res
|
||||
|
||||
|
||||
class ProcurementSchedulerLog(models.Model):
|
||||
_name = 'procurement.scheduler.log'
|
||||
_description = 'Logs of the Procurement Scheduler'
|
||||
_order = 'create_date desc'
|
||||
|
||||
company_id = fields.Many2one(
|
||||
'res.company', string='Company', readonly=True)
|
||||
start_datetime = fields.Datetime(string='Start Date', readonly=True)
|
||||
63
stock_usability/procurement_view.xml
Normal file
63
stock_usability/procurement_view.xml
Normal file
@@ -0,0 +1,63 @@
|
||||
<?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
|
||||
-->
|
||||
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<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">
|
||||
<field name="move_type" position="after">
|
||||
<field name="partner_id" readonly="True"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_procurement_form_stock_inherit" model="ir.ui.view">
|
||||
<field name="name">procurement_usability.procurement.order.form</field>
|
||||
<field name="model">procurement.order</field>
|
||||
<field name="inherit_id" ref="stock.view_procurement_form_stock_inherit"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='company_id']/.." position="after">
|
||||
<group name="move_ids" string="Stock Moves" colspan="4">
|
||||
<field name="move_ids" nolabel="1" readonly="True"/>
|
||||
</group>
|
||||
</xpath>
|
||||
<field name="partner_dest_id" position="before">
|
||||
<field name="orderpoint_id" readonly="True"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="procurement_scheduler_log_tree" model="ir.ui.view">
|
||||
<field name="name">procurement_scheduler_log_tree</field>
|
||||
<field name="model">procurement.scheduler.log</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Procurement Scheduler Logs">
|
||||
<field name="start_datetime"/>
|
||||
<field name="create_date" string="Scheduler End Time"/>
|
||||
<field name="create_uid" string="Scheduler Executed by"/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="procurement_scheduler_log_action" model="ir.actions.act_window">
|
||||
<field name="name">Scheduler Logs</field>
|
||||
<field name="res_model">procurement.scheduler.log</field>
|
||||
<field name="view_mode">tree</field>
|
||||
</record>
|
||||
|
||||
<menuitem id="procurement_scheduler_log_menu"
|
||||
action="procurement_scheduler_log_action"
|
||||
parent="stock.menu_stock_sched" sequence="22"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
3
stock_usability/security/ir.model.access.csv
Normal file
3
stock_usability/security/ir.model.access.csv
Normal file
@@ -0,0 +1,3 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_procurement_scheduler_log_full,Full access on procurement.scheduler.log to System group,model_procurement_scheduler_log,base.group_system,1,1,1,1
|
||||
access_procurement_scheduler_log_read,Read access on procurement.scheduler.log to Employee,model_procurement_scheduler_log,base.group_user,1,0,0,0
|
||||
|
@@ -103,21 +103,3 @@ class StockMove(models.Model):
|
||||
name = name + ' ' + fields.Date.to_string(date_expec_dt)
|
||||
res.append((line.id, name))
|
||||
return res
|
||||
|
||||
|
||||
class ProcurementOrder(models.Model):
|
||||
_inherit = "procurement.order"
|
||||
|
||||
def _procure_orderpoint_confirm(
|
||||
self, cr, uid, use_new_cursor=False, company_id=False,
|
||||
context=None):
|
||||
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)
|
||||
logger.info(
|
||||
'procurement scheduler: END creation of procurements from '
|
||||
'orderpoints')
|
||||
return res
|
||||
|
||||
Reference in New Issue
Block a user