Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions stock_lot_catalog_sale/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
======================
Sale Stock Lot Catalog
======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:0eab46e1d489196b0743bf39407b2ff7c1bfb9276439ca3e598b2be56d0f88c2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-warehouse/tree/18.0/stock_lot_catalog_sale
:alt: OCA/stock-logistics-warehouse
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-18-0/stock-logistics-warehouse-18-0-stock_lot_catalog_sale
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-warehouse&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

The Catalog lot control has been added to allow the use of the lot
catalog in sales orders.

**Table of contents**

.. contents::
:local:

Usage
=====

To access the lot catalog from a sales order.

1. Go to an existing sales order or create a new one.
2. In the order lines list there's a new option named *Catalog lot*.
3. Click it and start adding lots to the order.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-warehouse/issues>`_.
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
`feedback <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_lot_catalog_sale%0Aversion:%2018.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.

Credits
=======

Authors
-------

* Tecnativa

Contributors
------------

- `Tecnativa <https://www.tecnativa.com>`__:

- Pedro M. Baeza
- Víctor Martínez

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-victoralmau| image:: https://github.com/victoralmau.png?size=40px
:target: https://github.com/victoralmau
:alt: victoralmau

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-victoralmau|

This module is part of the `OCA/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/18.0/stock_lot_catalog_sale>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions stock_lot_catalog_sale/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions stock_lot_catalog_sale/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2026 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)

{
"name": "Sale Stock Lot Catalog",
"version": "18.0.1.0.0",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"author": "Tecnativa, Odoo Community Association (OCA)",
"category": "Warehouse",
"license": "AGPL-3",
"installable": True,
"depends": ["stock_lot_catalog", "sale_order_lot_selection"],
"data": [
"views/sale_order_views.xml",
],
"maintainers": ["victoralmau"],
}
36 changes: 36 additions & 0 deletions stock_lot_catalog_sale/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_lot_catalog_sale
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 18.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-04-21 09:05+0000\n"
"PO-Revision-Date: 2026-04-21 09:05+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: stock_lot_catalog_sale
#: model:ir.model.fields,field_description:stock_lot_catalog_sale.field_sale_order_line__lot_product_template_attribute_value_ids
msgid "Attribute Values"
msgstr "Valores de atributo"

#. module: stock_lot_catalog_sale
#: model_terms:ir.ui.view,arch_db:stock_lot_catalog_sale.view_order_form
msgid "Catalog lot"
msgstr "Catálogo de lotes"

#. module: stock_lot_catalog_sale
#: model:ir.model,name:stock_lot_catalog_sale.model_sale_order
msgid "Sales Order"
msgstr "Pedido de venta"

#. module: stock_lot_catalog_sale
#: model:ir.model,name:stock_lot_catalog_sale.model_sale_order_line
msgid "Sales Order Line"
msgstr "Línea de pedido de venta"
36 changes: 36 additions & 0 deletions stock_lot_catalog_sale/i18n/stock_lot_catalog_sale.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_lot_catalog_sale
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 18.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-04-21 09:04+0000\n"
"PO-Revision-Date: 2026-04-21 09:04+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: stock_lot_catalog_sale
#: model:ir.model.fields,field_description:stock_lot_catalog_sale.field_sale_order_line__lot_product_template_attribute_value_ids
msgid "Attribute Values"
msgstr ""

#. module: stock_lot_catalog_sale
#: model_terms:ir.ui.view,arch_db:stock_lot_catalog_sale.view_order_form
msgid "Catalog lot"
msgstr ""

#. module: stock_lot_catalog_sale
#: model:ir.model,name:stock_lot_catalog_sale.model_sale_order
msgid "Sales Order"
msgstr ""

#. module: stock_lot_catalog_sale
#: model:ir.model,name:stock_lot_catalog_sale.model_sale_order_line
msgid "Sales Order Line"
msgstr ""
1 change: 1 addition & 0 deletions stock_lot_catalog_sale/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sale_order
127 changes: 127 additions & 0 deletions stock_lot_catalog_sale/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# Copyright 2026 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from collections import defaultdict

from odoo import fields, models
from odoo.http import request
from odoo.osv import expression


class SaleOrder(models.Model):
_inherit = ["sale.order", "stock.lot.catalog.mixin"]
_name = "sale.order"

def _stock_lot_is_readonly(self):
self.ensure_one()
return self.state == "cancel" or self.locked

def _get_action_add_from_stock_lot_catalog_extra_context(self):
return {
**super()._get_action_add_from_stock_lot_catalog_extra_context(),
"lot_catalog_currency_id": self.currency_id.id,
"lot_catalog_digits": self.order_line._fields["price_unit"].get_digits(
self.env
),
}

def _get_stock_lot_catalog_order_domain(self):
extra_domain = [("product_id.sale_ok", "=", True)]
location = self.warehouse_id.lot_stock_id
extra_domain += [("location_id", "child_of", location.ids)]
return extra_domain

def _get_stock_lot_catalog_domain(self):
extra_domain = self._get_stock_lot_catalog_order_domain()
return expression.AND([super()._get_stock_lot_catalog_domain(), extra_domain])

def _get_stock_lot_catalog_record_lines(self, lot_ids, **kwargs):
grouped_lines = defaultdict(lambda: self.env["sale.order.line"])
for line in self.order_line.filtered(lambda x: x.lot_id):
if line.display_type or line.lot_id.id not in lot_ids:
continue
grouped_lines[line.lot_id] |= line
return grouped_lines

def _get_sol_from_stock_lot_catalog(self, lot_id):
"""This method returns the correct line and allows it to be extended to
other modules if necessary.
"""
return self.order_line.filtered(lambda line: line.lot_id.id == lot_id)

def _prepare_line_vals_from_stock_lot_catalog(self, lot, qty, **kwargs):
return {
"order_id": self.id,
"product_id": lot.product_id.id,
"product_uom_qty": qty,
"lot_id": lot.id,
"sequence": ((self.order_line and self.order_line[-1].sequence + 1) or 10),
}

def _update_lot_order_line_info(self, lot_id, quantity, **kwargs):
"""We need our own method instead of using the existing
_update_order_line_info() because, for example, it is not possible to filter
by the specific order line we need.
"""
request.update_context(catalog_skip_tracking=True)
lot = self.env["stock.lot"].browse(lot_id)
sol = self._get_sol_from_stock_lot_catalog(lot_id)
if sol:
if quantity != 0:
sol.product_uom_qty = quantity
elif self.state in ["draft", "sent"]:
price_unit = self.pricelist_id._get_product_price(
product=sol.product_id,
quantity=1.0,
currency=self.currency_id,
date=self.date_order,
**kwargs,
)
sol.unlink()
return price_unit
else:
sol.product_uom_qty = 0
elif quantity > 0:
sol_vals = self._prepare_line_vals_from_stock_lot_catalog(
lot, quantity, **kwargs
)
sol = self.env["sale.order.line"].create(sol_vals)
else: # quantity of 0, no line to update, return defaut pricelist price
return self.pricelist_id._get_product_price(
product=lot.product_id,
quantity=1.0,
currency=self.currency_id,
date=self.date_order,
**kwargs,
)
return sol._get_discounted_price()


class SaleOrderLine(models.Model):
_inherit = "sale.order.line"

lot_product_template_attribute_value_ids = fields.Many2many(
related="lot_id.product_template_attribute_value_ids",
depends=["lot_id"],
string="Lot Attribute Values",
)

def _get_stock_lot_catalog_lines_data(self, **kwargs):
product = self.product_id
res = {
"quantity": self.product_uom_qty,
"price": self._get_discounted_price(),
"readOnly": (
self.order_id._stock_lot_is_readonly()
or product.sale_line_warn == "block"
),
}
if (
product.sale_line_warn != "no-message"
and self.productproduct_id.sale_line_warn_msg
):
res["warning"] = product.sale_line_warn_msg
return res

def action_add_from_stock_lot_catalog(self):
order = self.env["sale.order"].browse(self.env.context.get("order_id"))
return order.action_add_from_stock_lot_catalog()
3 changes: 3 additions & 0 deletions stock_lot_catalog_sale/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
3 changes: 3 additions & 0 deletions stock_lot_catalog_sale/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- [Tecnativa](https://www.tecnativa.com):
- Pedro M. Baeza
- Víctor Martínez
1 change: 1 addition & 0 deletions stock_lot_catalog_sale/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The Catalog lot control has been added to allow the use of the lot catalog in sales orders.
5 changes: 5 additions & 0 deletions stock_lot_catalog_sale/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
To access the lot catalog from a sales order.

1. Go to an existing sales order or create a new one.
2. In the order lines list there's a new option named *Catalog lot*.
3. Click it and start adding lots to the order.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading