[imp] sale_order_batch: add in_progress and cancel state

This commit is contained in:
Niels Göttsch 2025-03-25 16:04:54 +01:00 committed by Niels Göttsch
parent d3de601798
commit 5215b3ee45
8 changed files with 69 additions and 34 deletions

View file

@ -40,6 +40,7 @@ Changelog
:1.1.0: Make validity_date persistent, add batches to SO views
:1.1.1: Remove validity date
:2.0.0: Move product logic to sale order lines
:2.1.0: Add "In Progress" and "Cancelled" state
Bug Tracker
===========

View file

@ -4,7 +4,7 @@
"author": "BAKEUP",
"website": "https://www.bakeup.org",
"category": "Sale",
"version": "16.0.2.0.0",
"version": "16.0.2.1.0",
"depends": ["sale", "product"],
"data": [
"data/ir_sequence_data.xml",

View file

@ -1,9 +1,8 @@
from odoo import _, api, fields, models
STATES = [("open", "Open"), ("close", "Close")]
READONLY_FIELD_STATES = {state: [("readonly", True)] for state in {"close"}}
STATES = [("open", "Open"), ("in_progress", "In Progress"), ("closed", "Closed"), ("cancel", "Cancelled")]
READONLY_FIELD_STATES = {state: [("readonly", True)] for state in {"closed"}}
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
)
state = fields.Selection(
selection=[("open", "Open"), ("closed", "Closed")],
string="Status",
readonly=True,
copy=False,
index=True,
tracking=1,
default="open",
selection=STATES, string="Status", readonly=True, copy=False, index=True, tracking=1, default="open"
)
date_order = fields.Datetime(
string="Order Date",
required=True,
readonly=False,
copy=False,
states={"closed": [("readonly", True)]},
states=READONLY_FIELD_STATES,
help="Creation date of order batch,\nConfirmation date of confirmed orders.",
default=fields.Datetime.now,
)
sale_order_ids = fields.One2many("sale.order", "batch_id")
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_count = fields.Integer(compute="_compute_invoice_ids")
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"}
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):
for batch in self:
orders = batch.with_context(bypass_batch=True).sale_order_ids
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
@api.model_create_multi

View file

@ -1,5 +1,7 @@
from odoo import api, fields, models
from .sale_order_batch import READONLY_FIELD_STATES
class SaleOrderBatchProduct(models.Model):
"""Show Products available in Sale Order Batch"""
@ -21,7 +23,7 @@ class SaleOrderBatchProduct(models.Model):
product_template_id = fields.Many2one(
"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_qty = fields.Float(compute="_compute_uom_qty", string="Quantity")
product_uom = fields.Many2one(related="product_id.uom_id")

View file

@ -4,3 +4,4 @@
:1.1.0: Make validity_date persistent, add batches to SO views
:1.1.1: Remove validity date
:2.0.0: Move product logic to sale order lines
:2.1.0: Add "In Progress" and "Cancelled" state

View file

@ -404,6 +404,8 @@ anymore as log as they are part of a batch. Only Sale Orders in state Qutotation
</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>
<tr class="field"><th class="field-name">2.1.0:</th><td class="field-body">Add “In Progress” and “Cancelled” state</td>
</tr>
</tbody>
</table>
</div>

View file

@ -5,6 +5,9 @@
<field name="model">sale.order.batch.product</field>
<field name="arch" type="xml">
<form>
<header>
<field name="state" invisible="1"/>
</header>
<sheet>
<div class="oe_button_box" name="button_box">
</div>
@ -23,12 +26,7 @@
</group>
<notebook>
<page string="Sale Order Lines" name="order_line">
<field name="state" invisible="1"/>
<field
name="sale_order_line_ids"
widget="section_and_note_one2many"
attrs="{'readonly': [('state', '=', 'closed')]}"
>
<field name="sale_order_line_ids" widget="section_and_note_one2many">
<tree editable="bottom" create="0">
<field name="company_id" invisible="1"/>
<field name="sequence" widget="handle"/>

View file

@ -21,6 +21,24 @@
<field name="arch" type="xml">
<form>
<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
name="action_confirm"
id="action_confirm"
@ -28,7 +46,7 @@
string="Confirm"
class="btn-primary"
type="object"
attrs="{'invisible': [('state', '!=','open')]}"
attrs="{'invisible': [('state', 'not in',['in_progress'])]}"
/>
<button
id="create_invoices"
@ -40,10 +58,18 @@
'default_sale_order_ids': sale_order_ids,
}"
data-hotkey="q"
attrs="{'invisible': [('state', '!=', 'closed')]}"
attrs="{'invisible': [('state', 'not in','closed')]}"
/>
<field name="state" widget="statusbar" options="{'clickable': 'true'}"/>
<button
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>
<div
class="alert alert-warning mb-0"
@ -90,7 +116,7 @@
<field name="amount_total" colspan="2" readonly="1"/>
</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" invisible="1" groups="!base.group_multi_company"/>
</group>
@ -117,11 +143,7 @@
</field>
</page>
<page string="Sale Order Lines" name="order_line">
<field
name="sale_order_line_ids"
widget="section_and_note_one2many"
attrs="{'readonly': [('state', 'in', ('closed'))]}"
>
<field name="sale_order_line_ids" widget="section_and_note_one2many">
<tree create="0" editable="bottom">
<field name="sequence" widget="handle"/>
<field name="order_id"/>
@ -162,13 +184,14 @@
<field name="model">sale.order.batch</field>
<field name="arch" type="xml">
<search>
<field name="name"/>
<filter string="Open" name="filter_batch_open" domain="[('state', '=', 'open')
]"/>
<filter string="Active" name="filter_batch_open" domain="[('state', 'in', ['open', 'in_progress'])]"/>
<filter string="To Invoice" name="filter_batch_to_invoice" domain="[('state', '=', 'closed')]"/>
<filter string="Cancelled" name="filter_batch_cancel" domain="[('state', '=', 'cancel')]"/>
</search>
</field>
</record>
<record id="action_batch" model="ir.actions.act_window">
<field name="name">Sale Order Batches</field>
<field name="type">ir.actions.act_window</field>