[IMP] sale_order_batch: apply pre-commit

This commit is contained in:
Niels Göttsch 2026-02-07 23:09:33 +01:00
parent 9c46372caf
commit e17935849c
13 changed files with 218 additions and 122 deletions

View file

@ -1,3 +1,7 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association
================ ================
Sale Order Batch Sale Order Batch
================ ================
@ -13,12 +17,12 @@ Sale Order Batch
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status :target: https://odoo-community.org/page/development-status
:alt: Beta :alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png .. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3 :alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-bakeupboys%2Fnfu-lightgray.png?logo=github .. |badge3| image:: https://img.shields.io/badge/github-madmooose%2Fodooapps-lightgray.png?logo=github
:target: https://github.com/bakeupboys/nfu/tree/16.0/sale_order_batch :target: https://github.com/madmooose/odooapps/tree/16.0/sale_order_batch
:alt: bakeupboys/nfu :alt: madmooose/odooapps
|badge1| |badge2| |badge3| |badge1| |badge2| |badge3|
@ -49,10 +53,10 @@ Changelog
Bug Tracker Bug Tracker
=========== ===========
Bugs are tracked on `GitHub Issues <https://github.com/bakeupboys/nfu/issues>`_. Bugs are tracked on `GitHub Issues <https://github.com/madmooose/odooapps/issues>`_.
In case of trouble, please check there if your issue has already been reported. In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/bakeupboys/nfu/issues/new?body=module:%20sale_order_batch%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. `feedback <https://github.com/madmooose/odooapps/issues/new?body=module:%20sale_order_batch%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues. Do not contact contributors directly about support or help with technical issues.
@ -63,6 +67,7 @@ Authors
~~~~~~~ ~~~~~~~
* BAKEUP * BAKEUP
* Niels Göttsch
Contributors Contributors
~~~~~~~~~~~~ ~~~~~~~~~~~~
@ -72,6 +77,6 @@ Contributors
Maintainers Maintainers
~~~~~~~~~~~ ~~~~~~~~~~~
This module is part of the `bakeupboys/nfu <https://github.com/bakeupboys/nfu/tree/16.0/sale_order_batch>`_ project on GitHub. This module is part of the `madmooose/odooapps <https://github.com/madmooose/odooapps/tree/16.0/sale_order_batch>`_ project on GitHub.
You are welcome to contribute. You are welcome to contribute.

View file

@ -1,8 +1,8 @@
{ {
"name": "Sale Order Batch", "name": "Sale Order Batch",
"summary": "Group Sale Orders into a batch", "summary": "Group Sale Orders into a batch",
"author": "BAKEUP", "author": "BAKEUP,Niels Göttsch",
"website": "https://www.bakeup.org", "website": "https://ziemlichoptimal.de",
"category": "Sale", "category": "Sale",
"version": "16.0.2.3.1", "version": "16.0.2.3.1",
"depends": ["sale", "product"], "depends": ["sale", "product"],

View file

@ -3,7 +3,6 @@ from odoo.exceptions import UserError
from odoo.addons.sale.models.sale_order import INVOICE_STATUS from odoo.addons.sale.models.sale_order import INVOICE_STATUS
STATES = [ STATES = [
("open", "Open"), ("open", "Open"),
("in_progress", "In Progress"), ("in_progress", "In Progress"),
@ -207,7 +206,8 @@ class SaleOrderBatch(models.Model):
self.write({"state": "cancel"}) self.write({"state": "cancel"})
def _show_cancel_wizard(self): def _show_cancel_wizard(self):
"""Decide whether the sale.order.batch.cancel wizard should be shown to cancel specified orders. """Decide whether the sale.order.batch.cancel wizard should be shown to cancel
specified orders.
:return: True if there is any non-draft order in the given orders :return: True if there is any non-draft order in the given orders
:rtype: bool :rtype: bool
@ -250,7 +250,8 @@ class SaleOrderBatchCancelWizard(models.TransientModel):
if not_draft_orders: if not_draft_orders:
raise UserError( raise UserError(
_( _(
"You can only cancel batches where all sale orders are in draft state." "You can only cancel batches where all sale orders are in "
"draft state."
) )
) )
# use _action_cancel to skip the wizzard # use _action_cancel to skip the wizzard

View file

@ -8,7 +8,7 @@ class SaleOrderLine(models.Model):
batch_product_id = fields.Many2one("sale.order.batch.product", ondelete="restrict") batch_product_id = fields.Many2one("sale.order.batch.product", ondelete="restrict")
def _link_batch_product(self): def _link_batch_product(self):
lines_with_batch = self.filtered(lambda l: l.batch_id) lines_with_batch = self.filtered(lambda line: line.batch_id)
for line in lines_with_batch: for line in lines_with_batch:
batch_id = line.batch_id batch_id = line.batch_id
batch_product = self.env["sale.order.batch.product"].search( batch_product = self.env["sale.order.batch.product"].search(
@ -25,17 +25,17 @@ class SaleOrderLine(models.Model):
line.batch_product_id = batch_product line.batch_product_id = batch_product
def _unlink_batch_product(self): def _unlink_batch_product(self):
lines_to_unlink = self.filtered(lambda l: l.batch_product_id) lines_to_unlink = self.filtered(lambda line: line.batch_product_id)
batch_products = lines_to_unlink.mapped("batch_product_id") batch_products = lines_to_unlink.mapped("batch_product_id")
lines_to_unlink.update({"batch_product_id": False}) lines_to_unlink.update({"batch_product_id": False})
batch_products.filtered(lambda p: len(p.sale_order_line_ids) == 0).unlink() batch_products.filtered(lambda p: len(p.sale_order_line_ids) == 0).unlink()
def _update_batch_product(self): def _update_batch_product(self):
lines_with_batch = self.filtered(lambda l: l.batch_id) lines_with_batch = self.filtered(lambda line: line.batch_id)
lines_without_batch = self - lines_with_batch lines_without_batch = self - lines_with_batch
lines_with_batch.filtered( lines_with_batch.filtered(
lambda l: l.batch_product_id lambda line: line.batch_product_id
and l.batch_product_id.product_id != l.product_id and line.batch_product_id.product_id != line.product_id
)._unlink_batch_product() )._unlink_batch_product()
lines_with_batch._link_batch_product() lines_with_batch._link_batch_product()
lines_without_batch._unlink_batch_product() lines_without_batch._unlink_batch_product()

View file

@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"

View file

@ -3,7 +3,7 @@
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" /> <meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>Sale Order Batch</title> <title>README.rst</title>
<style type="text/css"> <style type="text/css">
/* /*
@ -360,16 +360,21 @@ ul.auto-toc {
</style> </style>
</head> </head>
<body> <body>
<div class="document" id="sale-order-batch"> <div class="document">
<h1 class="title">Sale Order Batch</h1>
<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="sale-order-batch">
<h1>Sale Order Batch</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! <!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:6686f0672ede8093b17d5d7b165f72f8e49341c7849f9e0d5a162e350fc36d71 !! source digest: sha256:6686f0672ede8093b17d5d7b165f72f8e49341c7849f9e0d5a162e350fc36d71
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/bakeupboys/nfu/tree/16.0/sale_order_batch"><img alt="bakeupboys/nfu" src="https://img.shields.io/badge/github-bakeupboys%2Fnfu-lightgray.png?logo=github" /></a></p> <p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/madmooose/odooapps/tree/16.0/sale_order_batch"><img alt="madmooose/odooapps" src="https://img.shields.io/badge/github-madmooose%2Fodooapps-lightgray.png?logo=github" /></a></p>
<p>This module adds the possibility to group Sale orders into batches. Attributes of a Sale Order Batch will be written to all <p>This module adds the possibility to group Sale orders into batches. Attributes of a Sale Order Batch will be written to all
Sale Order. Wenn attached to a batch they can be processed together. On the other hand they cannot be proccesed individual Sale Order. Wenn attached to a batch they can be processed together. On the other hand they cannot be proccesed individual
anymore as log as they are part of a batch. Only Sale Orders in state Qutotation or Quotation Send can be attached to a batch.</p> anymore as log as they are part of a batch. Only Sale Orders in state Qutotation or Quotation Send can be attached to a batch.</p>
@ -387,7 +392,7 @@ anymore as log as they are part of a batch. Only Sale Orders in state Qutotation
</ul> </ul>
</div> </div>
<div class="section" id="changelog"> <div class="section" id="changelog">
<h1><a class="toc-backref" href="#toc-entry-1">Changelog</a></h1> <h2><a class="toc-backref" href="#toc-entry-1">Changelog</a></h2>
<ul class="simple"> <ul class="simple">
<li>16.0.0.0.1: Initial module.</li> <li>16.0.0.0.1: Initial module.</li>
<li>16.0.0.1: Add Multi Company ability</li> <li>16.0.0.1: Add Multi Company ability</li>
@ -403,33 +408,35 @@ anymore as log as they are part of a batch. Only Sale Orders in state Qutotation
</ul> </ul>
</div> </div>
<div class="section" id="bug-tracker"> <div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1> <h2><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h2>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/bakeupboys/nfu/issues">GitHub Issues</a>. <p>Bugs are tracked on <a class="reference external" href="https://github.com/madmooose/odooapps/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported. In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/bakeupboys/nfu/issues/new?body=module:%20sale_order_batch%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p> <a class="reference external" href="https://github.com/madmooose/odooapps/issues/new?body=module:%20sale_order_batch%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
<h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1> <h2><a class="toc-backref" href="#toc-entry-3">Credits</a></h2>
<div class="section" id="authors"> <div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2> <h3><a class="toc-backref" href="#toc-entry-4">Authors</a></h3>
<ul class="simple"> <ul class="simple">
<li>BAKEUP</li> <li>BAKEUP</li>
<li>Niels Göttsch</li>
</ul> </ul>
</div> </div>
<div class="section" id="contributors"> <div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2> <h3><a class="toc-backref" href="#toc-entry-5">Contributors</a></h3>
<ul class="simple"> <ul class="simple">
<li>Niels Göttsch &lt;<a class="reference external" href="mailto:niels&#64;ziemlichoptimal.de">niels&#64;ziemlichoptimal.de</a>&gt;</li> <li>Niels Göttsch &lt;<a class="reference external" href="mailto:niels&#64;ziemlichoptimal.de">niels&#64;ziemlichoptimal.de</a>&gt;</li>
</ul> </ul>
</div> </div>
<div class="section" id="maintainers"> <div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2> <h3><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h3>
<p>This module is part of the <a class="reference external" href="https://github.com/bakeupboys/nfu/tree/16.0/sale_order_batch">bakeupboys/nfu</a> project on GitHub.</p> <p>This module is part of the <a class="reference external" href="https://github.com/madmooose/odooapps/tree/16.0/sale_order_batch">madmooose/odooapps</a> project on GitHub.</p>
<p>You are welcome to contribute.</p> <p>You are welcome to contribute.</p>
</div> </div>
</div> </div>
</div> </div>
</div>
</body> </body>
</html> </html>

View file

@ -26,7 +26,10 @@
</group> </group>
<notebook> <notebook>
<page string="Sale Order Lines" name="order_line"> <page string="Sale Order Lines" name="order_line">
<field name="sale_order_line_ids" widget="section_and_note_one2many"> <field
name="sale_order_line_ids"
widget="section_and_note_one2many"
>
<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" />

View file

@ -7,8 +7,17 @@
<tree> <tree>
<field name="name" /> <field name="name" />
<field name="date_order" /> <field name="date_order" />
<field name="company_id" groups="base.group_multi_company" optional="show" readonly="1"/> <field
<field name="company_id" groups="!base.group_multi_company" invisible="1"/> name="company_id"
groups="base.group_multi_company"
optional="show"
readonly="1"
/>
<field
name="company_id"
groups="!base.group_multi_company"
invisible="1"
/>
<field name="sale_order_ids" widget="many2many_tags" /> <field name="sale_order_ids" widget="many2many_tags" />
<field <field
name="state" name="state"
@ -36,8 +45,17 @@
<tree> <tree>
<field name="name" /> <field name="name" />
<field name="date_order" /> <field name="date_order" />
<field name="company_id" groups="base.group_multi_company" optional="show" readonly="1"/> <field
<field name="company_id" groups="!base.group_multi_company" invisible="1"/> name="company_id"
groups="base.group_multi_company"
optional="show"
readonly="1"
/>
<field
name="company_id"
groups="!base.group_multi_company"
invisible="1"
/>
<field name="sale_order_ids" widget="many2many_tags" /> <field name="sale_order_ids" widget="many2many_tags" />
<field <field
name="state" name="state"
@ -131,7 +149,11 @@
icon="fa-pencil-square-o" icon="fa-pencil-square-o"
attrs="{'invisible': [('sale_order_count', '=', 0)]}" attrs="{'invisible': [('sale_order_count', '=', 0)]}"
> >
<field string="Sale Orders" name="sale_order_count" widget="statinfo"/> <field
string="Sale Orders"
name="sale_order_count"
widget="statinfo"
/>
</button> </button>
<button <button
class="oe_stat_button" class="oe_stat_button"
@ -140,7 +162,11 @@
icon="fa-cart-plus" icon="fa-cart-plus"
attrs="{'invisible': [('product_count', '=', 0)]}" attrs="{'invisible': [('product_count', '=', 0)]}"
> >
<field string="Products" name="product_count" widget="statinfo"/> <field
string="Products"
name="product_count"
widget="statinfo"
/>
</button> </button>
<button <button
name="action_view_invoice" name="action_view_invoice"
@ -149,7 +175,11 @@
icon="fa-pencil-square-o" icon="fa-pencil-square-o"
attrs="{'invisible': [('invoice_count', '=', 0)]}" attrs="{'invisible': [('invoice_count', '=', 0)]}"
> >
<field name="invoice_count" widget="statinfo" string="Invoices"/> <field
name="invoice_count"
widget="statinfo"
string="Invoices"
/>
</button> </button>
</div> </div>
<h1> <h1>
@ -161,8 +191,16 @@
</group> </group>
<group> <group>
<field name="date_order" /> <field name="date_order" />
<field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/> <field
<field name="company_id" invisible="1" groups="!base.group_multi_company"/> name="company_id"
options="{'no_create': True}"
groups="base.group_multi_company"
/>
<field
name="company_id"
invisible="1"
groups="!base.group_multi_company"
/>
</group> </group>
</group> </group>
<notebook> <notebook>
@ -195,7 +233,10 @@
</field> </field>
</page> </page>
<page string="Sale Order Lines" name="order_line"> <page string="Sale Order Lines" name="order_line">
<field name="sale_order_line_ids" widget="section_and_note_one2many"> <field
name="sale_order_line_ids"
widget="section_and_note_one2many"
>
<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" />
@ -217,8 +258,14 @@
<field name="product_id" /> <field name="product_id" />
<field name="product_uom_qty" /> <field name="product_uom_qty" />
<field name="lst_price" /> <field name="lst_price" />
<field name="product_packaging_qty" groups="product.group_stock_packaging"/> <field
<field name="product_packaging_id" groups="product.group_stock_packaging"/> name="product_packaging_qty"
groups="product.group_stock_packaging"
/>
<field
name="product_packaging_id"
groups="product.group_stock_packaging"
/>
</tree> </tree>
</field> </field>
</page> </page>
@ -237,9 +284,21 @@
<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>
<filter string="Active" name="filter_batch_open" domain="[('state', 'in', ['open', 'in_progress'])]"/> <filter
<filter string="Finished" name="filter_batch_finished" domain="[('state', '=', 'closed')]"/> string="Active"
<filter string="Cancelled" name="filter_batch_cancel" domain="[('state', '=', 'cancel')]"/> name="filter_batch_open"
domain="[('state', 'in', ['open', 'in_progress'])]"
/>
<filter
string="Finished"
name="filter_batch_finished"
domain="[('state', '=', 'closed')]"
/>
<filter
string="Cancelled"
name="filter_batch_cancel"
domain="[('state', '=', 'cancel')]"
/>
</search> </search>
</field> </field>
</record> </record>

View file

@ -23,15 +23,24 @@
icon="fa-tasks" icon="fa-tasks"
attrs="{'invisible': [('batch_id', '=', False)]}" attrs="{'invisible': [('batch_id', '=', False)]}"
> >
<field name="batch_id" attrs="{'readonly': True}"/> <field
name="batch_id"
attrs="{'readonly': True}"
/>
</button> </button>
</xpath> </xpath>
<xpath expr="//button[@name='action_confirm']" position="attributes"> <xpath
expr="//button[@name='action_confirm']"
position="attributes"
>
<attribute <attribute
name="attrs" name="attrs"
>{'invisible': ['|',('batch_id','!=',False),('state', 'not in', ['sent'])]}</attribute> >{'invisible': ['|',('batch_id','!=',False),('state', 'not in', ['sent'])]}</attribute>
</xpath> </xpath>
<xpath expr="//button[@name='action_confirm'][2]" position="attributes"> <xpath
expr="//button[@name='action_confirm'][2]"
position="attributes"
>
<attribute <attribute
name="attrs" name="attrs"
>{'invisible': ['|',('batch_id','!=',False),('state', 'not in', ['draft'])]}</attribute> >{'invisible': ['|',('batch_id','!=',False),('state', 'not in', ['draft'])]}</attribute>
@ -49,7 +58,11 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//tree" position="inside"> <xpath expr="//tree" position="inside">
<header> <header>
<button type="object" name="action_add_to_batch" string="Add to Batch"/> <button
type="object"
name="action_add_to_batch"
string="Add to Batch"
/>
</header> </header>
</xpath> </xpath>
<xpath expr="//field[@name='name']" position="after"> <xpath expr="//field[@name='name']" position="after">

View file

@ -15,7 +15,12 @@
</group> </group>
</group> </group>
<footer> <footer>
<button string="Cancel" name="action_cancel" type="object" class="btn-primary mx-1"/> <button
string="Cancel"
name="action_cancel"
type="object"
class="btn-primary mx-1"
/>
<button string="Discard" class="btn-secondary" special="cancel" /> <button string="Discard" class="btn-secondary" special="cancel" />
</footer> </footer>
</form> </form>