[IMP] stock_request_picking_type: black, isort, prettier

This commit is contained in:
ps-tubtim
2020-11-09 11:04:28 +07:00
committed by Reed Hayashikawa
parent 1a1eee7d9d
commit ef2be9c9d0
7 changed files with 272 additions and 147 deletions

View File

@@ -2,22 +2,19 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
{
'name': 'Stock Request Picking Type',
'summary': 'Add Stock Requests to the Inventory App',
'version': '12.0.2.1.1',
'license': 'LGPL-3',
'website': 'https://github.com/stock-logistics-warehouse',
'author': 'Open Source Integrators, '
'Odoo Community Association (OCA)',
'category': 'Warehouse',
'depends': [
'stock_request_submit',
"name": "Stock Request Picking Type",
"summary": "Add Stock Requests to the Inventory App",
"version": "13.0.1.0.0",
"license": "LGPL-3",
"website": "https://github.com/stock-logistics-warehouse",
"author": "Open Source Integrators, " "Odoo Community Association (OCA)",
"category": "Warehouse",
"depends": ["stock_request_submit"],
"data": [
"data/stock_picking_type.xml",
"views/stock_request_order_views.xml",
"views/stock_picking_views.xml",
],
'data': [
'data/stock_picking_type.xml',
'views/stock_request_order_views.xml',
'views/stock_picking_views.xml',
],
'development_status': 'Beta',
'maintainers': ['max3903']
"development_status": "Beta",
"maintainers": ["max3903"],
}

View File

@@ -1,10 +1,8 @@
<odoo noupdate="1">
<record id="stock_request_order" model="stock.picking.type">
<field name="name">Stock Requests</field>
<field name="sequence_id" ref="stock_request.seq_stock_request_order"/>
<field name="sequence_id" ref="stock_request.seq_stock_request_order" />
<field name="code">stock_request_order</field>
<field name="sequence">0</field>
</record>
</odoo>

View File

@@ -6,9 +6,11 @@ def migrate(env, version):
if not version:
return
env.execute("UPDATE stock_request_order "
"SET picking_type_id = ("
"SELECT id "
"FROM stock_picking_type "
"WHERE code = 'stock_request_order') "
"WHERE picking_type_id IS NULL;")
env.execute(
"UPDATE stock_request_order "
"SET picking_type_id = ("
"SELECT id "
"FROM stock_picking_type "
"WHERE code = 'stock_request_order') "
"WHERE picking_type_id IS NULL;"
)

View File

@@ -5,40 +5,44 @@ from odoo import fields, models
class StockPickingType(models.Model):
_inherit = 'stock.picking.type'
_inherit = "stock.picking.type"
code = fields.Selection(selection_add=[('stock_request_order',
'Stock Request Order')])
count_sr_todo = fields.Integer(string="To Do",
compute='_compute_sr_count')
count_sr_open = fields.Integer(string="In Progress",
compute='_compute_sr_count')
count_sr_late = fields.Integer(string="Late",
compute='_compute_sr_count')
code = fields.Selection(
selection_add=[("stock_request_order", "Stock Request Order")]
)
count_sr_todo = fields.Integer(string="To Do", compute="_compute_sr_count")
count_sr_open = fields.Integer(string="In Progress", compute="_compute_sr_count")
count_sr_late = fields.Integer(string="Late", compute="_compute_sr_count")
def _compute_sr_count(self):
types = self.filtered(
lambda picking: picking.code == 'stock_request_order')
types = self.filtered(lambda picking: picking.code == "stock_request_order")
if not types:
return
domains = {
'count_sr_todo': [('state', '=', 'submitted')],
'count_sr_open': [('state', '=', 'open')],
'count_sr_late': [('expected_date', '<', fields.Date.today()),
('state', 'in', ('submitted', 'open'))],
"count_sr_todo": [("state", "=", "submitted")],
"count_sr_open": [("state", "=", "open")],
"count_sr_late": [
("expected_date", "<", fields.Date.today()),
("state", "in", ("submitted", "open")),
],
}
for field in domains:
data = self.env['stock.request.order'].read_group(
domains[field] +
[('state', 'not in', ('done', 'cancel')),
('picking_type_id', 'in', self.ids)],
['picking_type_id'], ['picking_type_id'])
count = {x['picking_type_id'] and
x['picking_type_id'][0]: x['picking_type_id_count']
for x in data}
data = self.env["stock.request.order"].read_group(
domains[field]
+ [
("state", "not in", ("done", "cancel")),
("picking_type_id", "in", self.ids),
],
["picking_type_id"],
["picking_type_id"],
)
count = {
x["picking_type_id"]
and x["picking_type_id"][0]: x["picking_type_id_count"]
for x in data
}
for record in types:
record[field] = count.get(record.id, 0)
def get_stock_request_order_picking_type_action(self):
return self._get_action(
'stock_request_picking_type.action_picking_dashboard')
return self._get_action("stock_request_picking_type.action_picking_dashboard")

View File

@@ -5,36 +5,61 @@ from odoo import api, fields, models
class StockRequestOrder(models.Model):
_inherit = 'stock.request.order'
_inherit = "stock.request.order"
@api.model
def _get_default_picking_type(self):
return self.env['stock.picking.type'].search([
('code', '=', 'stock_request_order'),
('warehouse_id.company_id', 'in',
[self.env.context.get('company_id', self.env.user.company_id.id),
False])],
limit=1).id
return (
self.env["stock.picking.type"]
.search(
[
("code", "=", "stock_request_order"),
(
"warehouse_id.company_id",
"in",
[
self.env.context.get(
"company_id", self.env.user.company_id.id
),
False,
],
),
],
limit=1,
)
.id
)
picking_type_id = fields.Many2one(
'stock.picking.type', 'Operation Type',
default=_get_default_picking_type, required=True)
"stock.picking.type",
"Operation Type",
default=_get_default_picking_type,
required=True,
)
@api.onchange('warehouse_id')
@api.onchange("warehouse_id")
def onchange_warehouse_picking_id(self):
if self.warehouse_id:
picking_type_id = self.env['stock.picking.type'].\
search([('code', '=', 'stock_request_order'),
('warehouse_id', '=', self.warehouse_id.id)], limit=1)
picking_type_id = self.env["stock.picking.type"].search(
[
("code", "=", "stock_request_order"),
("warehouse_id", "=", self.warehouse_id.id),
],
limit=1,
)
if picking_type_id:
self._origin.write({'picking_type_id': picking_type_id.id})
self._origin.write({"picking_type_id": picking_type_id.id})
@api.model
def create(self, vals):
if vals.get('warehouse_id', False):
picking_type_id = self.env['stock.picking.type'].\
search([('code', '=', 'stock_request_order'),
('warehouse_id', '=', vals['warehouse_id'])], limit=1)
if vals.get("warehouse_id", False):
picking_type_id = self.env["stock.picking.type"].search(
[
("code", "=", "stock_request_order"),
("warehouse_id", "=", vals["warehouse_id"]),
],
limit=1,
)
if picking_type_id:
vals.update({'picking_type_id': picking_type_id.id})
vals.update({"picking_type_id": picking_type_id.id})
return super().create(vals)

View File

@@ -1,117 +1,196 @@
<?xml version="1.0" ?>
<odoo>
<record id="stock_request_type_kanban" model="ir.ui.view">
<field name="name">stock.picking.type.kanban</field>
<field name="model">stock.picking.type</field>
<field name="inherit_id" ref="stock.stock_picking_type_kanban"/>
<field name="inherit_id" ref="stock.stock_picking_type_kanban" />
<field name="arch" type="xml">
<field name="code" position="after">
<field name="count_sr_todo"/>
<field name="count_sr_open"/>
<field name="count_sr_late"/>
<field name="count_sr_todo" />
<field name="count_sr_open" />
<field name="count_sr_late" />
</field>
<xpath expr='//div[@name="stock_picking"]' position="after">
<div t-if="record.code.raw_value == 'stock_request_order'" t-attf-class="#{kanban_color(record.color.raw_value)}">
<div
t-if="record.code.raw_value == 'stock_request_order'"
t-attf-class="#{kanban_color(record.color.raw_value)}"
>
<div>
<div t-attf-class="o_kanban_card_header">
<div class="o_kanban_card_header_title">
<a type="object" name="get_stock_request_order_picking_type_action" class="o_primary">
<field name="name"/>
<a
type="object"
name="get_stock_request_order_picking_type_action"
class="o_primary"
>
<field name="name" />
</a>
<div class="o_secondary"><field class="o_secondary" name="warehouse_id"/></div>
<div class="o_secondary">
<field class="o_secondary" name="warehouse_id" />
</div>
</div>
<div class="o_kanban_manage_button_section">
<a class="o_kanban_manage_toggle_button" href="#"><i class="fa fa-ellipsis-v" role="img" aria-label="Manage" title="Manage"/></a>
<a class="o_kanban_manage_toggle_button" href="#">
<i
class="fa fa-ellipsis-v"
role="img"
aria-label="Manage"
title="Manage"
/>
</a>
</div>
</div>
<div class="container o_kanban_card_content">
<div class="row">
<div class="col-6 o_kanban_primary_left">
<button class="btn btn-primary" name="%(action_picking_dashboard)d" type="action" context="{'search_default_todo': 1}">
<span t-if="record.code.raw_value =='stock_request_order'"><t t-esc="record.count_sr_todo.value"/> To Process</span>
<button
class="btn btn-primary"
name="%(action_picking_dashboard)d"
type="action"
context="{'search_default_todo': 1}"
>
<span
t-if="record.code.raw_value =='stock_request_order'"
><t
t-esc="record.count_sr_todo.value"
/> To Process</span>
</button>
</div>
<div class="col-6 o_kanban_primary_right">
<div t-if="record.count_sr_open.raw_value > 0" class="row">
<div
t-if="record.count_sr_open.raw_value > 0"
class="row"
>
<div class="col-9">
<a name="%(action_picking_dashboard)d" type="action" context="{'search_default_inprogress': 1}">
<a
name="%(action_picking_dashboard)d"
type="action"
context="{'search_default_inprogress': 1}"
>
In Progress
</a>
</div>
<div class="col-3">
<field name="count_sr_open"/>
<field name="count_sr_open" />
</div>
</div>
<div t-if="record.count_sr_late.raw_value > 0" class="row">
<div
t-if="record.count_sr_late.raw_value > 0"
class="row"
>
<div class="col-9">
<a class="oe_kanban_stock_picking_type_list" name="%(action_picking_dashboard)d" type="action" context="{'search_default_late': 1}">
<a
class="oe_kanban_stock_picking_type_list"
name="%(action_picking_dashboard)d"
type="action"
context="{'search_default_late': 1}"
>
Late
</a>
</div>
<div class="col-3">
<field name="count_sr_late"/>
<field name="count_sr_late" />
</div>
</div>
</div>
</div>
</div><div class="container o_kanban_card_manage_pane dropdown-menu" role="menu">
<div class="row">
<div class="col-6 o_kanban_card_manage_section o_kanban_manage_view" name="picking_left_manage_pane">
<div role="menuitem" class="o_kanban_card_manage_title">
<span>View</span>
</div>
<div
class="container o_kanban_card_manage_pane dropdown-menu"
role="menu"
>
<div class="row">
<div
class="col-6 o_kanban_card_manage_section o_kanban_manage_view"
name="picking_left_manage_pane"
>
<div
role="menuitem"
class="o_kanban_card_manage_title"
>
<span>View</span>
</div>
<div role="menuitem">
<a
name="%(action_picking_dashboard)d"
type="action"
>All</a>
</div>
<div role="menuitem">
<a
name="%(action_picking_dashboard)d"
type="action"
context="{'search_default_todo': 1}"
>To Do</a>
</div>
<div role="menuitem">
<a
name="%(action_picking_dashboard)d"
type="action"
context="{'search_default_open': 1}"
>In Progress</a>
</div>
<div role="menuitem">
<a
name="%(action_picking_dashboard)d"
type="action"
context="{'search_default_done': 1}"
>Done</a>
</div>
</div>
<div role="menuitem">
<a name="%(action_picking_dashboard)d" type="action">All</a>
</div>
<div role="menuitem">
<a name="%(action_picking_dashboard)d" type="action" context="{'search_default_todo': 1}">To Do</a>
</div>
<div role="menuitem">
<a name="%(action_picking_dashboard)d" type="action" context="{'search_default_open': 1}">In Progress</a>
</div>
<div role="menuitem">
<a name="%(action_picking_dashboard)d" type="action" context="{'search_default_done': 1}">Done</a>
<div
class="col-6 o_kanban_card_manage_section o_kanban_manage_new"
>
<div
role="menuitem"
class="o_kanban_card_manage_title"
>
<span>New</span>
</div>
<div role="menuitem">
<a
name="%(action_stock_request_order_form)d"
type="action"
>Stock Request Order</a>
</div>
</div>
</div>
<div class="col-6 o_kanban_card_manage_section o_kanban_manage_new">
<div role="menuitem" class="o_kanban_card_manage_title">
<span>New</span>
<div
t-if="widget.editable"
class="o_kanban_card_manage_settings row"
>
<div role="menuitem" aria-haspopup="true" class="col-8">
<ul
role="menu"
class="oe_kanban_colorpicker"
data-field="color"
/>
</div>
<div role="menuitem">
<a name="%(action_stock_request_order_form)d" type="action">Stock Request Order</a>
<div role="menuitem" class="col-4 text-right">
<a type="edit">Settings</a>
</div>
</div>
</div>
<div t-if="widget.editable" class="o_kanban_card_manage_settings row">
<div role="menuitem" aria-haspopup="true" class="col-8">
<ul role="menu" class="oe_kanban_colorpicker" data-field="color"/>
</div>
<div role="menuitem" class="col-4 text-right">
<a type="edit">Settings</a>
</div>
</div>
</div>
</div>
</div>
</xpath>
</field>
</record>
<record id="view_picking_type_form_inherit_sro" model="ir.ui.view">
<field name="name">Operation Types</field>
<field name="model">stock.picking.type</field>
<field name="inherit_id" ref="stock.view_picking_type_form"/>
<field name="inherit_id" ref="stock.view_picking_type_form" />
<field name="arch" type="xml">
<field name="show_operations" position="attributes">
<attribute name="attrs">{"invisible": [("code", "=", "stock_request_order")]}</attribute>
<attribute
name="attrs"
>{"invisible": [("code", "=", "stock_request_order")]}</attribute>
</field>
<field name="show_reserved" position="attributes">
<attribute name="attrs">{"invisible": [("code", "=", "stock_request_order")]}</attribute>
<attribute
name="attrs"
>{"invisible": [("code", "=", "stock_request_order")]}</attribute>
</field>
</field>
</record>
</odoo>

View File

@@ -1,38 +1,58 @@
<odoo>
<record id="view_stock_request_order_filter" model="ir.ui.view">
<field name="name">stock.request.order.select</field>
<field name="model">stock.request.order</field>
<field name="arch" type="xml">
<search string="Search Stock Request Orders">
<field name="name"/>
<filter string="To Do" name="todo" domain="[('state','=', 'submitted')]"
help="Stock Requests To Do."/>
<filter string="In Progress" name="inprogress" domain="[('state', '=', 'open')]"
help="Stock Requests in Progress."/>
<filter string="Late" domain="['&amp;', ('expected_date', '&lt;', current_date), ('state', 'in', ('submitted', 'open'))]"
name="late" help="Late Stock Requests"/>
<filter string="Done" name="done" domain="[('state', '=', 'done')]"/>
<field name="name" />
<filter
string="To Do"
name="todo"
domain="[('state','=', 'submitted')]"
help="Stock Requests To Do."
/>
<filter
string="In Progress"
name="inprogress"
domain="[('state', '=', 'open')]"
help="Stock Requests in Progress."
/>
<filter
string="Late"
domain="['&amp;', ('expected_date', '&lt;', current_date), ('state', 'in', ('submitted', 'open'))]"
name="late"
help="Late Stock Requests"
/>
<filter string="Done" name="done" domain="[('state', '=', 'done')]" />
<group expand="0" string="Group By...">
<filter string="Expected Date" name="expected_date" domain="[]" context="{'group_by': 'expected_date'}" help="Expected Date by Month"/>
<filter string="State" name="state" domain="[]" context="{'group_by': 'state'}"/>
<filter
string="Expected Date"
name="expected_date"
domain="[]"
context="{'group_by': 'expected_date'}"
help="Expected Date by Month"
/>
<filter
string="State"
name="state"
domain="[]"
context="{'group_by': 'state'}"
/>
</group>
</search>
</field>
</record>
<record id="action_picking_dashboard" model="ir.actions.act_window">
<field name="name">Stock Request Orders</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">stock.request.order</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" eval="False"/>
<field name="search_view_id" ref="view_stock_request_order_filter"/>
<field name="view_id" eval="False" />
<field name="search_view_id" ref="view_stock_request_order_filter" />
<field name="domain">[('picking_type_id', '=', active_id)]</field>
<field name="context">{'default_picking_type_id': active_id}</field>
</record>
<record id="action_stock_request_order_form" model="ir.actions.act_window">
<field name="name">Stock Request Orders</field>
<field name="type">ir.actions.act_window</field>
@@ -40,11 +60,11 @@
<field name="view_type">form</field>
<field name="view_mode">form</field>
</record>
<menuitem id="menu_stock_request_order"
action="stock_request.stock_request_order_action"
name="Stock Request Orders"
parent="stock.menu_stock_warehouse_mgmt"
sequence="30"/>
<menuitem
id="menu_stock_request_order"
action="stock_request.stock_request_order_action"
name="Stock Request Orders"
parent="stock.menu_stock_warehouse_mgmt"
sequence="30"
/>
</odoo>