[add] wizzard proto code
TODO: add new models to security file
This commit is contained in:
parent
b021c89d67
commit
b2d4830a77
7 changed files with 160 additions and 25 deletions
|
|
@ -17,12 +17,12 @@ NFU Sale Min Max Quantitiy
|
||||||
: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-bruecksen%2Fife_nfu-lightgray.png?logo=github
|
.. |badge3| image:: https://img.shields.io/badge/github-bruecksen%2Fife_nfu-lightgray.png?logo=github
|
||||||
:target: https://github.com/bakeupboys/nfu/tree/16.0/nfu_sale_product_min_max_qty
|
:target: https://github.com/bruecksen/ife_nfu/tree/16.0/nfu_sale_product_min_max_qty
|
||||||
:alt: bruecksen/ife_nfu
|
:alt: bruecksen/ife_nfu
|
||||||
|
|
||||||
|badge1| |badge2| |badge3|
|
|badge1| |badge2| |badge3|
|
||||||
|
|
||||||
This module adds a minium and a maximum order quantity field to Sale Orders and the Webshop.
|
This module adds a minium and a maximum order quantity field to Sale Orders and adds it to checkout of the website shop.
|
||||||
|
|
||||||
**Table of contents**
|
**Table of contents**
|
||||||
|
|
||||||
|
|
@ -37,10 +37,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/bruecksen/ife_nfu/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:%20nfu_sale_product_min_max_qty%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
`feedback <https://github.com/bruecksen/ife_nfu/issues/new?body=module:%20nfu_sale_product_min_max_qty%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.
|
||||||
|
|
||||||
|
|
@ -61,6 +61,6 @@ Contributors
|
||||||
Maintainers
|
Maintainers
|
||||||
~~~~~~~~~~~
|
~~~~~~~~~~~
|
||||||
|
|
||||||
This module is part of the `bruecksen/ife_nfu <https://github.com/bakeupboys/nfu/tree/16.0/nfu_sale_product_min_max_qty>`_ project on GitHub.
|
This module is part of the `bruecksen/ife_nfu <https://github.com/bruecksen/ife_nfu/tree/16.0/nfu_sale_product_min_max_qty>`_ project on GitHub.
|
||||||
|
|
||||||
You are welcome to contribute.
|
You are welcome to contribute.
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,37 @@
|
||||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||||
|
|
||||||
from odoo import _, fields, models
|
from odoo import _, models
|
||||||
|
|
||||||
|
|
||||||
class SaleOrder(models.Model):
|
class SaleOrder(models.Model):
|
||||||
_inherit = 'sale.order'
|
_inherit = "sale.order"
|
||||||
|
|
||||||
def action_min_max_qty_wizard(self):
|
def action_min_max_qty_wizard(self):
|
||||||
|
"""
|
||||||
|
Here you need to create the wizzard objects first and then call the wizzard with the newly created id
|
||||||
|
|
||||||
|
sale_order_lines = self.env[sale.order.line].search[id in self.order_line.ids]
|
||||||
|
|
||||||
|
sale_max_qty_chooser = self.env["sale.max.qty.chooser"].create({})
|
||||||
|
|
||||||
|
for line in sale_order_lines:
|
||||||
|
if not display_type:
|
||||||
|
sale_max_qty_line = self.env["sale.max.qty.line"].create({"sale_line_id": self.id,
|
||||||
|
"sale_max_qty_chooser": sale_max_qty_chooser,
|
||||||
|
"qty": ....
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
action = {
|
||||||
|
"name": _("Min max qty wizard"),
|
||||||
|
"type": "ir.actions.act_window",
|
||||||
|
"res_model": "sale.max.qty.chooser",
|
||||||
|
"view_mode": "form",
|
||||||
|
"target": "new",
|
||||||
|
"res_id": sale_max_qty_chooser.id,
|
||||||
|
}
|
||||||
|
return action
|
||||||
|
"""
|
||||||
return {
|
return {
|
||||||
"name": _("Min max qty wizard"),
|
"name": _("Min max qty wizard"),
|
||||||
"type": "ir.actions.act_window",
|
"type": "ir.actions.act_window",
|
||||||
|
|
@ -16,25 +41,33 @@ class SaleOrder(models.Model):
|
||||||
}
|
}
|
||||||
|
|
||||||
def _prepare_order_line_values(
|
def _prepare_order_line_values(
|
||||||
self, product_id, quantity, linked_line_id=False,
|
self,
|
||||||
no_variant_attribute_values=None, product_custom_attribute_values=None,
|
product_id,
|
||||||
|
quantity,
|
||||||
|
linked_line_id=False,
|
||||||
|
no_variant_attribute_values=None,
|
||||||
|
product_custom_attribute_values=None,
|
||||||
**kwargs
|
**kwargs
|
||||||
):
|
):
|
||||||
values = super()._prepare_order_line_values(product_id, quantity, linked_line_id=linked_line_id, no_variant_attribute_values=no_variant_attribute_values, product_custom_attribute_values=product_custom_attribute_values, **kwargs)
|
values = super()._prepare_order_line_values(
|
||||||
values.update({
|
product_id,
|
||||||
'product_uom_min_qty': quantity,
|
quantity,
|
||||||
'product_uom_max_qty': kwargs.get('max_qty', quantity),
|
linked_line_id=linked_line_id,
|
||||||
})
|
no_variant_attribute_values=no_variant_attribute_values,
|
||||||
|
product_custom_attribute_values=product_custom_attribute_values,
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
|
values.update({"product_uom_min_qty": quantity, "product_uom_max_qty": kwargs.get("max_qty", quantity)})
|
||||||
return values
|
return values
|
||||||
|
|
||||||
def _prepare_order_line_update_values(
|
def _prepare_order_line_update_values(self, order_line, quantity, linked_line_id=False, **kwargs):
|
||||||
self, order_line, quantity, linked_line_id=False, **kwargs
|
values = super()._prepare_order_line_update_values(
|
||||||
):
|
order_line, quantity, linked_line_id=linked_line_id, **kwargs
|
||||||
values = super()._prepare_order_line_update_values(order_line, quantity, linked_line_id=linked_line_id, **kwargs)
|
)
|
||||||
max_qty = kwargs.get('max_qty', quantity)
|
max_qty = kwargs.get("max_qty", quantity)
|
||||||
if quantity != order_line.product_uom_min_qty:
|
if quantity != order_line.product_uom_min_qty:
|
||||||
values['product_uom_min_qty'] = quantity
|
values["product_uom_min_qty"] = quantity
|
||||||
if max_qty and max_qty != order_line.product_uom_max_qty:
|
if max_qty and max_qty != order_line.product_uom_max_qty:
|
||||||
values['product_uom_max_qty'] = max_qty
|
values["product_uom_max_qty"] = max_qty
|
||||||
|
|
||||||
return values
|
return values
|
||||||
|
|
|
||||||
|
|
@ -370,7 +370,7 @@ ul.auto-toc {
|
||||||
!! source digest: sha256:4dfaea54e4d01502b433eb5c0dcca409a5fbe2c3f175e29382a19230343183c9
|
!! source digest: sha256:4dfaea54e4d01502b433eb5c0dcca409a5fbe2c3f175e29382a19230343183c9
|
||||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||||
<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/bruecksen/ife_nfu/tree/16.0/nfu_sale_product_min_max_qty"><img alt="bruecksen/ife_nfu" src="https://img.shields.io/badge/github-bruecksen%2Fife_nfu-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/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/bruecksen/ife_nfu/tree/16.0/nfu_sale_product_min_max_qty"><img alt="bruecksen/ife_nfu" src="https://img.shields.io/badge/github-bruecksen%2Fife_nfu-lightgray.png?logo=github" /></a></p>
|
||||||
<p>This module adds a minium and a maximum order quantity field to Sale Orders</p>
|
<p>This module adds a minium and a maximum order quantity field to Sale Orders and adds it to checkout of the website shop.</p>
|
||||||
<p><strong>Table of contents</strong></p>
|
<p><strong>Table of contents</strong></p>
|
||||||
<div class="contents local topic" id="contents">
|
<div class="contents local topic" id="contents">
|
||||||
<ul class="simple">
|
<ul class="simple">
|
||||||
|
|
@ -415,6 +415,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
|
||||||
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
|
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
|
||||||
<ul class="simple">
|
<ul class="simple">
|
||||||
<li>Niels Göttsch <<a class="reference external" href="mailto:niels@ziemlichoptimal.de">niels@ziemlichoptimal.de</a>></li>
|
<li>Niels Göttsch <<a class="reference external" href="mailto:niels@ziemlichoptimal.de">niels@ziemlichoptimal.de</a>></li>
|
||||||
|
<li>Matthias Brück <<a class="reference external" href="mailto:hi@brueck.io">hi@brueck.io</a>></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="maintainers">
|
<div class="section" id="maintainers">
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,11 @@
|
||||||
<record id="view_order_list_inherit_product_min_max_qty" model="ir.ui.view">
|
<record id="view_order_list_inherit_product_min_max_qty" model="ir.ui.view">
|
||||||
<field name="name">sale.order.list.view.inherited</field>
|
<field name="name">sale.order.list.view.inherited</field>
|
||||||
<field name="model">sale.order</field>
|
<field name="model">sale.order</field>
|
||||||
<field name="inherit_id" ref="sale.view_quotation_tree_with_onboarding"/>
|
<field name="inherit_id" ref="sale.view_quotation_tree"/>
|
||||||
<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_min_max_qty_wizard" string="Min/Max Wizard" class="btn btn-primary"/>
|
<button type="object" name="action_min_max_qty_wizard" string="Min/Max Wizard"/>
|
||||||
</header>
|
</header>
|
||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
|
|
|
||||||
45
nfu_sale_product_min_max_qty/wizzard/sale_max_qty_chooser.py
Normal file
45
nfu_sale_product_min_max_qty/wizzard/sale_max_qty_chooser.py
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class SaleMaxQtyChooser(models.TransientModel):
|
||||||
|
"""Wizard to Allow user to adjust the sale order amout to fit to a packaging size"""
|
||||||
|
|
||||||
|
_name = "sale.max.qty.chooser"
|
||||||
|
_description = "Sale Max Quantity Chhooser"
|
||||||
|
|
||||||
|
# fill from init or compute from given sale order lines
|
||||||
|
sale_order_ids = fields.Many2many("sale.order")
|
||||||
|
sale_max_qty_ids = fields.One2many("sale.max.qty.line", "mrp_return_id")
|
||||||
|
|
||||||
|
def confirm_qty_sale_order(self):
|
||||||
|
"""
|
||||||
|
Confirm sale orders where the quantity is fine. Create new Sale Orders for SO Lines with reset to draft
|
||||||
|
Through user error when total order amount of a product is not equal to packaging size (first package in the
|
||||||
|
list or smalles package sale_order_line.product_id.product.packaging_ids.qty)
|
||||||
|
we can use write({'key':'value'}) to update all sale order lines and action_confirm() to validate all sale
|
||||||
|
orders
|
||||||
|
|
||||||
|
Also see this methode on how to create new records. It creates a invoice with invoice lines. we need to do the
|
||||||
|
same for sale orders
|
||||||
|
|
||||||
|
def action_sold(self):
|
||||||
|
res = super().action_sold()
|
||||||
|
self.env["account.move"].create(
|
||||||
|
{
|
||||||
|
"property_id": self.id,
|
||||||
|
"partner_id": self.buyer_id.id,
|
||||||
|
"move_type": "out_invoice",
|
||||||
|
"line_ids": [
|
||||||
|
fields.Command.create(
|
||||||
|
{
|
||||||
|
"name": f"Property {self.name} - 10% Tax",
|
||||||
|
"quantity": 1,
|
||||||
|
"price_unit": self.selling_price * 1.1,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
fields.Command.create({"name": "Administration Fees", "quantity": 1, "price_unit": 1000}),
|
||||||
|
],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return res
|
||||||
|
"""
|
||||||
16
nfu_sale_product_min_max_qty/wizzard/sale_max_qty_line.py
Normal file
16
nfu_sale_product_min_max_qty/wizzard/sale_max_qty_line.py
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class SaleMaxQtyLine(models.TransientModel):
|
||||||
|
"""
|
||||||
|
Lines to shown in Wizard
|
||||||
|
"""
|
||||||
|
|
||||||
|
_name = "sale.max.qty.line"
|
||||||
|
_description = "Max qty Sale Order Lines"
|
||||||
|
|
||||||
|
sale_max_qty_chooser = fields.Many2one("sale.max.qty.chooser")
|
||||||
|
qty = fields.Float()
|
||||||
|
sale_line_id = fields.Many2one("sale.order.line")
|
||||||
|
product_id = fields.Many2one(related="sale_line_id.product_id")
|
||||||
|
reset_to_draft = fields.Boolean()
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<record id="view_sale_max_qty_chooser_form" model="ir.ui.view">
|
||||||
|
<field name="name">Sale Max Quantity Chhooser</field>
|
||||||
|
<field name="model">sale.max.qty.chooser</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form>
|
||||||
|
<div class="oe_grey">
|
||||||
|
<p>Headline</p>
|
||||||
|
</div>
|
||||||
|
<field name="sale_max_qty_ids">
|
||||||
|
<tree create="0">
|
||||||
|
<!-- Make this field read only -->
|
||||||
|
<field name="product_id"/>
|
||||||
|
<field name="qty"/>
|
||||||
|
<field name="reset_to_draft"/>
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
<footer>
|
||||||
|
<button
|
||||||
|
name="confirm_qty_sale_order"
|
||||||
|
string="Confirm Sale Orders"
|
||||||
|
type="object"
|
||||||
|
class="btn-primary"
|
||||||
|
data-hotkey="q"
|
||||||
|
/>
|
||||||
|
<button string="Cancel" class="btn-secondary" special="cancel" data-hotkey="z"/>
|
||||||
|
</footer>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="action_sale_max_qty" model="ir.actions.act_window">
|
||||||
|
<field name="name">Set Quantities</field>
|
||||||
|
<field name="res_model">sale.max.qty.chooser</field>
|
||||||
|
<field name="view_mode">form</field>
|
||||||
|
<field name="target">new</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
Loading…
Reference in a new issue