Skip to content

Commit

Permalink
[MIG] pos_default_quantity: Migration to 16.0
Browse files Browse the repository at this point in the history
Signed-off-by: Carmen Bianca BAKKER <carmen@coopiteasy.be>
  • Loading branch information
carmenbianca committed Sep 27, 2024
1 parent 2c57c0c commit e8d9efa
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 110 deletions.
14 changes: 13 additions & 1 deletion pos_default_quantity/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,26 @@ Set Default Product Quantity in POS

This module adds a field for a default quantity to Unit of Measure Categories.
When this is filled in, and when this functionality is enabled in the Point of
Sale Configuration, then adding that product to an order in the Point of Sale
Sale configuration, then adding that product to an order in the Point of Sale
will set the quantity to that value by default.

**Table of contents**

.. contents::
:local:

Configuration
=============

In order to set this up, you need to do a few things:

- Make sure that you have permissions to manage multiple units of measure.
- In the settings of Inventory, enable units of measure.
- For each relevant unit of measure category, determine a default product quantity
(default: 1).
- For each relevant Point of Sale, find 'Set default product quantity' in the
'Inventory' section of its settings, and toggle it on.

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

Expand Down
10 changes: 7 additions & 3 deletions pos_default_quantity/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Set Default Product Quantity in POS",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"author": "Coop IT Easy SC, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/pos",
"license": "AGPL-3",
Expand All @@ -15,8 +15,12 @@
""",
"depends": ["point_of_sale"],
"data": [
"views/pos_config_views.xml",
"views/res_config_settings_views.xml",
"views/uom_category_views.xml",
"static/src/xml/templates.xml",
],
"assets": {
"point_of_sale.assets": [
"pos_default_quantity/static/src/js/**/*.js",
]
},
}
3 changes: 3 additions & 0 deletions pos_default_quantity/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
from . import pos_config
from . import pos_session
from . import product_template
from . import res_config_settings
from . import uom_category
2 changes: 1 addition & 1 deletion pos_default_quantity/models/pos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ class PosConfig(models.Model):
_inherit = "pos.config"

set_default_product_quantity = fields.Boolean(
string="Sets default product quantity in POS", default=False
string="Set default product quantity in POS", default=False
)
14 changes: 14 additions & 0 deletions pos_default_quantity/models/pos_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later

from odoo import models


class PosSession(models.Model):
_inherit = "pos.session"

def _loader_params_product_product(self):
result = super()._loader_params_product_product()
result["search_params"]["fields"].append("pos_default_qty")
return result
11 changes: 11 additions & 0 deletions pos_default_quantity/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later

from odoo import fields, models


class ProductTemplate(models.Model):
_inherit = "product.template"

pos_default_qty = fields.Float(related="uom_id.category_id.pos_default_qty")
14 changes: 14 additions & 0 deletions pos_default_quantity/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later

from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

pos_set_default_product_quantity = fields.Boolean(
related="pos_config_id.set_default_product_quantity",
readonly=False,
)
7 changes: 6 additions & 1 deletion pos_default_quantity/models/uom_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@
class UoMCategory(models.Model):
_inherit = "uom.category"

pos_default_qty = fields.Float(string="POS Default Quantity", default=1)
# TODO: Should this be hidden behind a boolean toggle?
pos_default_qty = fields.Float(
string="POS Default Quantity",
required=True,
default=1,
)
8 changes: 8 additions & 0 deletions pos_default_quantity/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
In order to set this up, you need to do a few things:

- Make sure that you have permissions to manage multiple units of measure.
- In the settings of Inventory, enable units of measure.
- For each relevant unit of measure category, determine a default product quantity
(default: 1).
- For each relevant Point of Sale, find 'Set default product quantity' in the
'Inventory' section of its settings, and toggle it on.
2 changes: 1 addition & 1 deletion pos_default_quantity/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This module adds a field for a default quantity to Unit of Measure Categories.
When this is filled in, and when this functionality is enabled in the Point of
Sale Configuration, then adding that product to an order in the Point of Sale
Sale configuration, then adding that product to an order in the Point of Sale
will set the quantity to that value by default.
35 changes: 24 additions & 11 deletions pos_default_quantity/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -371,45 +371,58 @@ <h1 class="title">Set Default Product Quantity in POS</h1>
<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/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/pos/tree/16.0/pos_default_quantity"><img alt="OCA/pos" src="https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/pos-16-0/pos-16-0-pos_default_quantity"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/pos&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module adds a field for a default quantity to Unit of Measure Categories.
When this is filled in, and when this functionality is enabled in the Point of
Sale Configuration, then adding that product to an order in the Point of Sale
Sale configuration, then adding that product to an order in the Point of Sale
will set the quantity to that value by default.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-1">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-2">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-3">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-4">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-5">Maintainers</a></li>
<li><a class="reference internal" href="#configuration" id="toc-entry-1">Configuration</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-2">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="configuration">
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<p>In order to set this up, you need to do a few things:</p>
<ul class="simple">
<li>Make sure that you have permissions to manage multiple units of measure.</li>
<li>In the settings of Inventory, enable units of measure.</li>
<li>For each relevant unit of measure category, determine a default product quantity
(default: 1).</li>
<li>For each relevant Point of Sale, find ‘Set default product quantity’ in the
‘Inventory’ section of its settings, and toggle it on.</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/pos/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/pos/issues/new?body=module:%20pos_default_quantity%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>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#toc-entry-2">Credits</a></h1>
<h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-3">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<ul class="simple">
<li>Coop IT Easy SC</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<ul class="simple">
<li>Robin Keunen &lt;<a class="reference external" href="mailto:robin.keunen&#64;coopiteasy.be">robin.keunen&#64;coopiteasy.be</a>&gt;</li>
<li>Vincent Van Rossem &lt;<a class="reference external" href="mailto:vincent&#64;coopiteasy.be">vincent&#64;coopiteasy.be</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
Expand Down
26 changes: 26 additions & 0 deletions pos_default_quantity/static/src/js/models.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/** @odoo-module alias=pos_default_quantity.models **/
// SPDX-FileCopyrightText: 2024 Coop IT Easy SC
//
// SPDX-License-Identifier: AGPL-3.0-or-later

import {Orderline} from "point_of_sale.models";
import Registries from "point_of_sale.Registries";

const DefaultQtyOrderline = (Orderline) =>
class DefaultQtyOrderline extends Orderline {
constructor(obj, options) {
super(obj, options);

// Don't set default quantity on restored lines
if (options.json) {
return;
}

if (this.pos.config.set_default_product_quantity) {
this.set_quantity(this.product.pos_default_qty);
}
}
};

Registries.Model.extend(Orderline, DefaultQtyOrderline);
export default DefaultQtyOrderline;
47 changes: 0 additions & 47 deletions pos_default_quantity/static/src/js/pos.js

This file was deleted.

17 changes: 0 additions & 17 deletions pos_default_quantity/static/src/xml/templates.xml

This file was deleted.

28 changes: 0 additions & 28 deletions pos_default_quantity/views/pos_config_views.xml

This file was deleted.

27 changes: 27 additions & 0 deletions pos_default_quantity/views/res_config_settings_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" ?>
<odoo>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field
name="name"
>res.config.settings.view.form.inherit.pos_default_quantity</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="point_of_sale.res_config_settings_view_form" />
<field name="arch" type="xml">
<xpath expr="//div[@id='pos_inventory_section']" position="inside">
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="pos_set_default_product_quantity" />
</div>
<div class="o_setting_right_pane">
<label for="pos_set_default_product_quantity" />
<div class="text-muted">
When enabled, adding a product sets the quantity to
a default configured on the Unit of Measure
Category.
</div>
</div>
</div>
</xpath>
</field>
</record>
</odoo>

0 comments on commit e8d9efa

Please sign in to comment.