[imp] sale_order_batch: add in_progress and cancel state
This commit is contained in:
parent
ef3f1785ba
commit
06a114bffc
8 changed files with 69 additions and 34 deletions
|
|
@ -40,6 +40,7 @@ Changelog
|
||||||
:1.1.0: Make validity_date persistent, add batches to SO views
|
:1.1.0: Make validity_date persistent, add batches to SO views
|
||||||
:1.1.1: Remove validity date
|
:1.1.1: Remove validity date
|
||||||
:2.0.0: Move product logic to sale order lines
|
:2.0.0: Move product logic to sale order lines
|
||||||
|
:2.1.0: Add "In Progress" and "Cancelled" state
|
||||||
|
|
||||||
Bug Tracker
|
Bug Tracker
|
||||||
===========
|
===========
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
"author": "BAKEUP",
|
"author": "BAKEUP",
|
||||||
"website": "https://www.bakeup.org",
|
"website": "https://www.bakeup.org",
|
||||||
"category": "Sale",
|
"category": "Sale",
|
||||||
"version": "16.0.2.0.0",
|
"version": "16.0.2.1.0",
|
||||||
"depends": ["sale", "product"],
|
"depends": ["sale", "product"],
|
||||||
"data": [
|
"data": [
|
||||||
"data/ir_sequence_data.xml",
|
"data/ir_sequence_data.xml",
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
from odoo import _, api, fields, models
|
from odoo import _, api, fields, models
|
||||||
|
|
||||||
|
|
||||||
STATES = [("open", "Open"), ("close", "Close")]
|
STATES = [("open", "Open"), ("in_progress", "In Progress"), ("closed", "Closed"), ("cancel", "Cancelled")]
|
||||||
|
READONLY_FIELD_STATES = {state: [("readonly", True)] for state in {"closed"}}
|
||||||
READONLY_FIELD_STATES = {state: [("readonly", True)] for state in {"close"}}
|
|
||||||
|
|
||||||
|
|
||||||
class SaleOrderBatch(models.Model):
|
class SaleOrderBatch(models.Model):
|
||||||
|
|
@ -27,26 +26,20 @@ class SaleOrderBatch(models.Model):
|
||||||
comodel_name="res.company", required=True, index=True, default=lambda self: self.env.company
|
comodel_name="res.company", required=True, index=True, default=lambda self: self.env.company
|
||||||
)
|
)
|
||||||
state = fields.Selection(
|
state = fields.Selection(
|
||||||
selection=[("open", "Open"), ("closed", "Closed")],
|
selection=STATES, string="Status", readonly=True, copy=False, index=True, tracking=1, default="open"
|
||||||
string="Status",
|
|
||||||
readonly=True,
|
|
||||||
copy=False,
|
|
||||||
index=True,
|
|
||||||
tracking=1,
|
|
||||||
default="open",
|
|
||||||
)
|
)
|
||||||
date_order = fields.Datetime(
|
date_order = fields.Datetime(
|
||||||
string="Order Date",
|
string="Order Date",
|
||||||
required=True,
|
required=True,
|
||||||
readonly=False,
|
readonly=False,
|
||||||
copy=False,
|
copy=False,
|
||||||
states={"closed": [("readonly", True)]},
|
states=READONLY_FIELD_STATES,
|
||||||
help="Creation date of order batch,\nConfirmation date of confirmed orders.",
|
help="Creation date of order batch,\nConfirmation date of confirmed orders.",
|
||||||
default=fields.Datetime.now,
|
default=fields.Datetime.now,
|
||||||
)
|
)
|
||||||
sale_order_ids = fields.One2many("sale.order", "batch_id")
|
sale_order_ids = fields.One2many("sale.order", "batch_id")
|
||||||
sale_order_count = fields.Integer(compute="_compute_sale_order_count")
|
sale_order_count = fields.Integer(compute="_compute_sale_order_count")
|
||||||
sale_order_line_ids = fields.One2many("sale.order.line", "batch_id")
|
sale_order_line_ids = fields.One2many("sale.order.line", "batch_id", states=READONLY_FIELD_STATES)
|
||||||
invoice_ids = fields.Many2many("account.move", compute="_compute_invoice_ids")
|
invoice_ids = fields.Many2many("account.move", compute="_compute_invoice_ids")
|
||||||
invoice_count = fields.Integer(compute="_compute_invoice_ids")
|
invoice_count = fields.Integer(compute="_compute_invoice_ids")
|
||||||
amount_total = fields.Float(compute="_compute_amount_total", string="Total")
|
amount_total = fields.Float(compute="_compute_amount_total", string="Total")
|
||||||
|
|
@ -126,11 +119,26 @@ class SaleOrderBatch(models.Model):
|
||||||
action["context"] = {"default_move_type": "out_invoice"}
|
action["context"] = {"default_move_type": "out_invoice"}
|
||||||
return action
|
return action
|
||||||
|
|
||||||
|
def action_in_progress(self):
|
||||||
|
for batch in self:
|
||||||
|
batch.sale_order_line_ids._validate_analytic_distribution()
|
||||||
|
orders = batch.sale_order_ids
|
||||||
|
orders.update({"state": "sent"})
|
||||||
|
batch.update({"state": "in_progress"})
|
||||||
|
return True
|
||||||
|
|
||||||
def action_confirm(self):
|
def action_confirm(self):
|
||||||
for batch in self:
|
for batch in self:
|
||||||
orders = batch.with_context(bypass_batch=True).sale_order_ids
|
orders = batch.with_context(bypass_batch=True).sale_order_ids
|
||||||
orders.action_confirm()
|
orders.action_confirm()
|
||||||
batch.state = "closed"
|
batch.update({"state": "closed"})
|
||||||
|
return True
|
||||||
|
|
||||||
|
def action_cancel(self):
|
||||||
|
for batch in self:
|
||||||
|
orders = batch.sale_order_ids
|
||||||
|
orders.action_cancel()
|
||||||
|
batch.update({"state": "cancel"})
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@api.model_create_multi
|
@api.model_create_multi
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
from odoo import api, fields, models
|
from odoo import api, fields, models
|
||||||
|
|
||||||
|
from .sale_order_batch import READONLY_FIELD_STATES
|
||||||
|
|
||||||
|
|
||||||
class SaleOrderBatchProduct(models.Model):
|
class SaleOrderBatchProduct(models.Model):
|
||||||
"""Show Products available in Sale Order Batch"""
|
"""Show Products available in Sale Order Batch"""
|
||||||
|
|
@ -21,7 +23,7 @@ class SaleOrderBatchProduct(models.Model):
|
||||||
product_template_id = fields.Many2one(
|
product_template_id = fields.Many2one(
|
||||||
"product.template", related="product_id.product_tmpl_id", string="Product Template"
|
"product.template", related="product_id.product_tmpl_id", string="Product Template"
|
||||||
)
|
)
|
||||||
sale_order_line_ids = fields.One2many("sale.order.line", "batch_product_id")
|
sale_order_line_ids = fields.One2many("sale.order.line", "batch_product_id", states=READONLY_FIELD_STATES)
|
||||||
product_uom_category_id = fields.Many2one(related="product_id.uom_id.category_id", depends=["product_id"])
|
product_uom_category_id = fields.Many2one(related="product_id.uom_id.category_id", depends=["product_id"])
|
||||||
product_uom_qty = fields.Float(compute="_compute_uom_qty", string="Quantity")
|
product_uom_qty = fields.Float(compute="_compute_uom_qty", string="Quantity")
|
||||||
product_uom = fields.Many2one(related="product_id.uom_id")
|
product_uom = fields.Many2one(related="product_id.uom_id")
|
||||||
|
|
|
||||||
|
|
@ -4,3 +4,4 @@
|
||||||
:1.1.0: Make validity_date persistent, add batches to SO views
|
:1.1.0: Make validity_date persistent, add batches to SO views
|
||||||
:1.1.1: Remove validity date
|
:1.1.1: Remove validity date
|
||||||
:2.0.0: Move product logic to sale order lines
|
:2.0.0: Move product logic to sale order lines
|
||||||
|
:2.1.0: Add "In Progress" and "Cancelled" state
|
||||||
|
|
|
||||||
|
|
@ -404,6 +404,8 @@ anymore as log as they are part of a batch. Only Sale Orders in state Qutotation
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="field"><th class="field-name">2.0.0:</th><td class="field-body">Move product logic to sale order lines</td>
|
<tr class="field"><th class="field-name">2.0.0:</th><td class="field-body">Move product logic to sale order lines</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr class="field"><th class="field-name">2.1.0:</th><td class="field-body">Add “In Progress” and “Cancelled” state</td>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,9 @@
|
||||||
<field name="model">sale.order.batch.product</field>
|
<field name="model">sale.order.batch.product</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form>
|
<form>
|
||||||
|
<header>
|
||||||
|
<field name="state" invisible="1"/>
|
||||||
|
</header>
|
||||||
<sheet>
|
<sheet>
|
||||||
<div class="oe_button_box" name="button_box">
|
<div class="oe_button_box" name="button_box">
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -23,12 +26,7 @@
|
||||||
</group>
|
</group>
|
||||||
<notebook>
|
<notebook>
|
||||||
<page string="Sale Order Lines" name="order_line">
|
<page string="Sale Order Lines" name="order_line">
|
||||||
<field name="state" invisible="1"/>
|
<field name="sale_order_line_ids" widget="section_and_note_one2many">
|
||||||
<field
|
|
||||||
name="sale_order_line_ids"
|
|
||||||
widget="section_and_note_one2many"
|
|
||||||
attrs="{'readonly': [('state', '=', 'closed')]}"
|
|
||||||
>
|
|
||||||
<tree editable="bottom" create="0">
|
<tree editable="bottom" create="0">
|
||||||
<field name="company_id" invisible="1"/>
|
<field name="company_id" invisible="1"/>
|
||||||
<field name="sequence" widget="handle"/>
|
<field name="sequence" widget="handle"/>
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,24 @@
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form>
|
<form>
|
||||||
<header>
|
<header>
|
||||||
|
<button
|
||||||
|
name="action_in_progress"
|
||||||
|
id="action_in_progress"
|
||||||
|
data-hotkey="g"
|
||||||
|
string="In Progress"
|
||||||
|
class="btn-primary"
|
||||||
|
type="object"
|
||||||
|
attrs="{'invisible': [('state', 'not in',['open'])]}"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
name="action_confirm"
|
||||||
|
id="action_confirm"
|
||||||
|
data-hotkey="v"
|
||||||
|
string="Confirm"
|
||||||
|
class="btn-secondary"
|
||||||
|
type="object"
|
||||||
|
attrs="{'invisible': [('state', 'not in',['open'])]}"
|
||||||
|
/>
|
||||||
<button
|
<button
|
||||||
name="action_confirm"
|
name="action_confirm"
|
||||||
id="action_confirm"
|
id="action_confirm"
|
||||||
|
|
@ -28,7 +46,7 @@
|
||||||
string="Confirm"
|
string="Confirm"
|
||||||
class="btn-primary"
|
class="btn-primary"
|
||||||
type="object"
|
type="object"
|
||||||
attrs="{'invisible': [('state', '!=','open')]}"
|
attrs="{'invisible': [('state', 'not in',['in_progress'])]}"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
id="create_invoices"
|
id="create_invoices"
|
||||||
|
|
@ -40,10 +58,18 @@
|
||||||
'default_sale_order_ids': sale_order_ids,
|
'default_sale_order_ids': sale_order_ids,
|
||||||
}"
|
}"
|
||||||
data-hotkey="q"
|
data-hotkey="q"
|
||||||
attrs="{'invisible': [('state', '!=', 'closed')]}"
|
attrs="{'invisible': [('state', 'not in','closed')]}"
|
||||||
/>
|
/>
|
||||||
|
<button
|
||||||
<field name="state" widget="statusbar" options="{'clickable': 'true'}"/>
|
name="action_cancel"
|
||||||
|
id="action_cancel"
|
||||||
|
data-hotkey="z"
|
||||||
|
string="Cancel"
|
||||||
|
class="btn-secondary"
|
||||||
|
type="object"
|
||||||
|
attrs="{'invisible': [('state', 'not in',['open', 'in_progress','closed'])]}"
|
||||||
|
/>
|
||||||
|
<field name="state" widget="statusbar"/>
|
||||||
</header>
|
</header>
|
||||||
<div
|
<div
|
||||||
class="alert alert-warning mb-0"
|
class="alert alert-warning mb-0"
|
||||||
|
|
@ -90,7 +116,7 @@
|
||||||
<field name="amount_total" colspan="2" readonly="1"/>
|
<field name="amount_total" colspan="2" readonly="1"/>
|
||||||
</group>
|
</group>
|
||||||
<group>
|
<group>
|
||||||
<field name="date_order" attrs="{'readonly': [('state','=','closed')]}"/>
|
<field name="date_order"/>
|
||||||
<field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
|
<field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
|
||||||
<field name="company_id" invisible="1" groups="!base.group_multi_company"/>
|
<field name="company_id" invisible="1" groups="!base.group_multi_company"/>
|
||||||
</group>
|
</group>
|
||||||
|
|
@ -117,11 +143,7 @@
|
||||||
</field>
|
</field>
|
||||||
</page>
|
</page>
|
||||||
<page string="Sale Order Lines" name="order_line">
|
<page string="Sale Order Lines" name="order_line">
|
||||||
<field
|
<field name="sale_order_line_ids" widget="section_and_note_one2many">
|
||||||
name="sale_order_line_ids"
|
|
||||||
widget="section_and_note_one2many"
|
|
||||||
attrs="{'readonly': [('state', 'in', ('closed'))]}"
|
|
||||||
>
|
|
||||||
<tree create="0" editable="bottom">
|
<tree create="0" editable="bottom">
|
||||||
<field name="sequence" widget="handle"/>
|
<field name="sequence" widget="handle"/>
|
||||||
<field name="order_id"/>
|
<field name="order_id"/>
|
||||||
|
|
@ -162,13 +184,14 @@
|
||||||
<field name="model">sale.order.batch</field>
|
<field name="model">sale.order.batch</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<search>
|
<search>
|
||||||
<field name="name"/>
|
<filter string="Active" name="filter_batch_open" domain="[('state', 'in', ['open', 'in_progress'])]"/>
|
||||||
<filter string="Open" name="filter_batch_open" domain="[('state', '=', 'open')
|
<filter string="To Invoice" name="filter_batch_to_invoice" domain="[('state', '=', 'closed')]"/>
|
||||||
]"/>
|
<filter string="Cancelled" name="filter_batch_cancel" domain="[('state', '=', 'cancel')]"/>
|
||||||
</search>
|
</search>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
|
||||||
<record id="action_batch" model="ir.actions.act_window">
|
<record id="action_batch" model="ir.actions.act_window">
|
||||||
<field name="name">Sale Order Batches</field>
|
<field name="name">Sale Order Batches</field>
|
||||||
<field name="type">ir.actions.act_window</field>
|
<field name="type">ir.actions.act_window</field>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue