[WIP] project_exception: file structure for the new module

This commit is contained in:
percyhibou
2022-09-28 23:07:43 +00:00
parent d957c043bb
commit 7b2076a49d
12 changed files with 215 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
from . import models
from . import wizard

View File

@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
{
'name': "Project Exception Rule",
'summary': """
Module for Project Exception Rule""",
'description': """
The ability to run and trigger exceptions to block the moving of a task based on rules
""",
'author': "Hibou Corp.",
'website': "http://www.hibou.io/",
# Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/15.0/odoo/addons/base/data/ir_module_category_data.xml
# for the full list
'category': 'Generic Modules',
'version': '15.0.1.0.0',
'license': 'OPL-1',
# any module necessary for this one to work correctly
'depends': ['base_exception_user', 'project'],
# always loaded
'data': [
'security/ir.model.access.csv',
'views/project_views.xml',
'wizard/project_exception_confirm_views.xml',
],
# only loaded in demonstration mode
'demo': [
'demo/project_exception_demo.xml',
],
'installable': True,
'auto_install': False,
}

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="except_no_project_id" model="exception.rule">
<field name="name">No Project Id</field>
<field name="description">No Project Id</field>
<field name="sequence">50</field>
<field name="model">project</field>
<field name="code">if not project_id: failed=True</field>
<field name="active" eval="False"/>
</record>
</odoo>

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import models

View File

@@ -0,0 +1,44 @@
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
from odoo import api, models, fields
class ExceptionRule(models.Model):
_inherit = 'exception.rule'
model = fields.Selection(
selection_add=[
('stock.picking', 'Transfer'),
],
ondelete={
'stock.picking': 'cascade',
},
)
picking_ids = fields.Many2many(
'stock.picking',
string="Transfers")
class Picking(models.Model):
_inherit = ['stock.picking', 'base.exception']
_name = 'stock.picking'
_order = 'main_exception_id asc, priority desc, date asc, id desc'
@api.model
def _exception_rule_eval_context(self, rec):
res = super(Picking, self)._exception_rule_eval_context(rec)
res['picking'] = rec
return res
@api.model
def _reverse_field(self):
return 'picking_ids'
def button_validate(self):
self.ensure_one()
if self.detect_exceptions():
return self._popup_exceptions()
return super().button_validate()
@api.model
def _get_popup_action(self):
return self.env.ref('stock_exception.action_stock_exception_confirm')

View File

@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_project_task_exception_confirm_project_task,project_task_exception.project_task_exception,model_project_task_exception_confirm,project.group_project_user,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_project_task_exception_confirm_project_task project_task_exception.project_task_exception model_project_task_exception_confirm project.group_project_user 1 1 1 1

View File

@@ -0,0 +1,2 @@
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
from . import test_project_exception

View File

@@ -0,0 +1,43 @@
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
from odoo.tests import common, Form
class TestProjectException(common.TransactionCase):
def setUp(self):
super().setUp()
self.env = self.env(context=dict(self.env.context, tracking_disable=True))
def test_project_task_creation_exception(self):
exception = self.env.ref('project_exception.except_no_project_id')
exception.active = True
# partner = self.env.ref('base.res_partner_12') # Azure Interior
# partner.zip = False
# p = self.env.ref('product.product_product_6')
# stock_location = self.env.ref('stock.stock_location_stock')
# customer_location = self.env.ref('stock.stock_location_customers')
# self.env['stock.quant']._update_available_quantity(p, stock_location, 100)
# delivery_order = self.env['stock.picking'].create({
# 'partner_id': partner.id,
# 'picking_type_id': self.ref('stock.picking_type_out'),
# 'location_id': self.env.ref('stock.stock_location_stock').id,
# 'location_dest_id': self.env.ref('stock.stock_location_customers').id,
# 'move_line_ids': [(0, 0, {'product_id': p.id,
# 'product_uom_id': p.uom_id.id,
# 'qty_done': 3.0,
# 'location_id': stock_location.id,
# 'location_dest_id': customer_location.id})],
# })
# validate delivery order
# action = delivery_order.button_validate()
# self.assertEqual(delivery_order.state, 'draft')
# Simulation the opening of the wizard sale_exception_confirm and
# set ignore_exception to True
# stock_exception_confirm = Form(self.env[action['res_model']].with_context(action['context'])).save()
# stock_exception_confirm.ignore = True
# stock_exception_confirm.action_confirm()
# self.assertTrue(delivery_order.ignore_exception)
# self.assertEqual(delivery_order.state, 'done')

View File

@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="action_stock_test_tree" model="ir.actions.act_window">
<field name="name">Stock Exception Rules</field>
<field name="res_model">exception.rule</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="base_exception.view_exception_rule_tree"/>
<field name="domain">[('model', '=', 'stock.picking')]</field>
<field name="context">{'active_test': False, 'default_model' : 'stock.picking'}</field>
</record>
<menuitem
action="action_stock_test_tree"
id="menu_stock_test"
sequence="10"
parent="stock.menu_stock_config_settings"
groups="base_exception.group_exception_rule_manager"
/>
<record id="view_picking_form" model="ir.ui.view">
<field name="name">stock.picking.form.inherit.exception</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<sheet position="before">
<div class="alert alert-danger" role="alert" style="margin-bottom:0px;"
attrs="{'invisible': [('exceptions_summary','=',False)]}">
<p><strong>There are exceptions blocking the confirmation of this Delivery Order:</strong></p>
<field name="exceptions_summary"/>
<button name="action_ignore_exceptions" type="object" class="btn-danger"
string="Ignore Exceptions" help="Click here to be able to confirm this Delivery Order regardless of the exceptions."
groups="base_exception.group_exception_rule_manager"/>
</div>
</sheet>
<xpath expr="//field[@name='origin']/.." position="inside">
<field name="ignore_exception" states="done" />
</xpath>
</field>
</record>
<record id="view_picking_tree" model="ir.ui.view">
<field name="name">stock.picking.tree.inherit.exception</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.vpicktree"/>
<field name="arch" type="xml">
<field name="state" position="after">
<field name="main_exception_id"/>
</field>
</field>
</record>
<record id="view_picking_internal_search" model="ir.ui.view">
<field name="name">stock.picking.internal.search.inherit.exception</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_internal_search" />
<field name="arch" type="xml">
<filter name="backorder" position="after">
<separator orientation="vertical"/>
<filter icon="terp-emblem-important" name="tofix" string="Blocked by exceptions" domain="[('main_exception_id','!=',False)]"/>
</filter>
</field>
</record>
</odoo>

View File

@@ -0,0 +1 @@
from . import project_exception_confim