Skip to content

Commit

Permalink
update sale_quotation and add shopinvader_sale_state
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieu.saison committed Nov 27, 2023
1 parent 6a8dde2 commit e667997
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 96 deletions.
2 changes: 1 addition & 1 deletion sale_quotation/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Sale Quotation
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:5135646a34800340d4d881beccc1dca8cc79c1fc0c607a5eae841535581e0774
!! source digest: sha256:0b385df82e12b7547593361d9083b791ef182af861cad60fa9425f2845de77ac
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
Expand Down
2 changes: 1 addition & 1 deletion sale_quotation/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"website": "https://github.com/shopinvader/odoo-shopinvader",
"author": "Akretion",
"license": "AGPL-3",
"depends": ["sale"],
"depends": ["sale", "shopinvader_sale_state"],
"data": [
"views/product_view.xml",
"views/sale_view.xml",
Expand Down
33 changes: 21 additions & 12 deletions sale_quotation/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
class ProductTemplate(models.Model):
_inherit = "product.template"

shop_only_quotation = fields.Boolean(
shop_only_quotation = fields.Selection(
selection=[
("all_variant", "All Variant"),
("manually_on_variant", "Manually on Variant"),
("never", "Never"),
],
string="Shopinvader: Only for Quotation",
compute="_compute_shop_only_quotation",
inverse="_inverse_shop_only_quotation",
Expand All @@ -20,23 +25,27 @@ class ProductTemplate(models.Model):
def _compute_shop_only_quotation(self):
# True only if true for all its variants
for rec in self:
rec.shop_only_quotation = (
all(rec.product_variant_ids.mapped("shop_only_quotation"))
if rec.product_variant_ids
else False
)
if not rec.product_variant_ids or not any(
rec.product_variant_ids.mapped("shop_only_quotation")
):
rec.shop_only_quotation = "never"
elif all(rec.product_variant_ids.mapped("shop_only_quotation")):
rec.shop_only_quotation = "all_variant"
elif any(rec.product_variant_ids.mapped("shop_only_quotation")):
rec.shop_only_quotation = "manually_on_variant"

def _inverse_shop_only_quotation(self):
# Sets the value on all its variants
for rec in self:
rec.product_variant_ids.shop_only_quotation = rec.shop_only_quotation
if rec.shop_only_quotation == "all_variant":
rec.product_variant_ids.shop_only_quotation = True
elif rec.shop_only_quotation == "never":
rec.product_variant_ids.shop_only_quotation = False

def _create_variant_ids(self):
# Make sure new variants have the same value than the template.
templates = self.filtered("shop_only_quotation")
res = super()._create_variant_ids()
products = templates.product_variant_ids.filtered(
lambda rec: not rec.shop_only_quotation
)
products.shop_only_quotation = True
for rec in self:
if rec.shop_only_quotation == "all_variant":
rec.product_variant_ids.shop_only_quotation = True
return res
51 changes: 18 additions & 33 deletions sale_quotation/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# @author Benoît GUILLOT <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


from odoo import _, fields, models
from odoo.exceptions import UserError

Expand All @@ -14,27 +15,8 @@ class SaleOrder(models.Model):
selection_add=[("quotation", "Quotation")],
ondelete={"quotation": "cascade"},
)
shopinvader_state = fields.Selection(
selection_add=[
("estimating", "Estimating Quotation"),
("estimated", "Estimated Quotation"),
],
ondelete={
"estimating": "cascade",
"estimated": "cascade",
},
)

def _compute_shopinvader_state_depends(self):
return super()._compute_shopinvader_state_depends() + ("typology",)

def _get_shopinvader_state(self):
self.ensure_one()
if self.typology == "quotation" and self.state == "draft":
return "estimating"
if self.typology == "quotation" and self.state == "sent":
return "estimated"
return super()._get_shopinvader_state()
available_for_quotation = fields.Boolean(compute="_compute_available_for_quotation")
shop_only_quotation = fields.Boolean(compute="_compute_shop_only_quotation")

def action_request_quotation(self):
if any(rec.state != "draft" or rec.typology != "cart" for rec in self):
Expand All @@ -46,15 +28,18 @@ def action_request_quotation(self):
)
for rec in self:
rec.typology = "quotation"
if rec.shopinvader_backend_id:
rec.shopinvader_backend_id._send_notification("quotation_request", rec)
return True

def write(self, vals):
# Set the typology to "quotation" when the quotation is sent.
# Normally there are two cases where this happens:
# * When the :meth:`action_quotation_sent` is called.
# * When a message is posted with context `mark_so_as_sent=True`.
if vals.get("state") == "sent":
vals["typology"] = "quotation"
return super().write(vals)
return self

def _compute_available_for_quotation(self):
for record in self:
record.available_for_quotation = True

def _compute_shop_only_quotation(self):
for record in self:
record.shop_only_quotation = any(
record.order_line.product_id.mapped("shop_only_quotation")
)

def action_confirm_quotation(self):
self.typology = "sale"
return self.action_confirm()
2 changes: 1 addition & 1 deletion sale_quotation/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Sale Quotation</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:5135646a34800340d4d881beccc1dca8cc79c1fc0c607a5eae841535581e0774
!! source digest: sha256:0b385df82e12b7547593361d9083b791ef182af861cad60fa9425f2845de77ac
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.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/shopinvader/odoo-shopinvader/tree/16.0/sale_quotation"><img alt="shopinvader/odoo-shopinvader" src="https://img.shields.io/badge/github-shopinvader%2Fodoo--shopinvader-lightgray.png?logo=github" /></a></p>
<p>This module handle the model and view for product and sale.order needs for shopinvader-api-quotation</p>
Expand Down
1 change: 1 addition & 0 deletions sale_quotation/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_product
20 changes: 0 additions & 20 deletions sale_quotation/tests/test_notification.py

This file was deleted.

19 changes: 6 additions & 13 deletions sale_quotation/tests/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def setUpClass(cls):

def test_simple_product(self):
# Back and forth flow, setting and reading on template and single variant
self.assertFalse(self.product_template.shop_only_quotation)
self.product_template.shop_only_quotation = True
self.assertEqual(self.product_template.shop_only_quotation, "never")
self.product_template.shop_only_quotation = "all_variant"
self.assertTrue(self.product_template.product_variant_ids.shop_only_quotation)
self.product_template.product_variant_ids.shop_only_quotation = False
self.assertFalse(self.product_template.shop_only_quotation)
self.assertEqual(self.product_template.shop_only_quotation, "never")

def test_multi_product(self):
# Configure product with multiple variants
Expand All @@ -44,22 +44,15 @@ def test_multi_product(self):
product_1 = self.product_template.product_variant_ids[0]
product_2 = self.product_template.product_variant_ids[1]
# Set on the template should set all variants
template.shop_only_quotation = True
template.shop_only_quotation = "all_variant"
self.assertTrue(product_1.shop_only_quotation)
self.assertTrue(product_2.shop_only_quotation)
# Set a variant to false should set the template to false
# It's only true if it's true for all variants
product_1.shop_only_quotation = False
self.assertFalse(template.shop_only_quotation)
self.assertEqual(template.shop_only_quotation, "manually_on_variant")
self.assertTrue(product_2.shop_only_quotation, "Other variant shouldn't change")
# Set false on template should set all variants to false
template.shop_only_quotation = False
template.shop_only_quotation = "never"
self.assertFalse(product_1.shop_only_quotation)
self.assertFalse(product_2.shop_only_quotation)
# Create a new variant combination should copy the value from template
template.shop_only_quotation = True
value_3 = self.value_2.copy({"name": "Another color"})
template.attribute_line_ids.value_ids = [(4, value_3.id)]
self.assertEqual(len(self.product_template.product_variant_ids), 3)
product_3 = self.product_template.product_variant_ids - (product_1 | product_2)
self.assertTrue(product_3.shop_only_quotation)
13 changes: 4 additions & 9 deletions sale_quotation/views/product_view.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>

<record id="view_product_template_form" model="ir.ui.view">
<record id="product_template_form_view" model="ir.ui.view">
<field name="model">product.template</field>
<field name="inherit_id" ref="shopinvader.view_product_template_form" />
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml">
<group name="shopinvader_options" position="attributes">
<attribute name="invisible">0</attribute>
</group>
<group name="shopinvader_options" position="inside">
<field name="categ_id" position="after">
<field name="shop_only_quotation" string="Only for Quotation" />
</group>
</field>
</field>
</record>

</odoo>
12 changes: 6 additions & 6 deletions sale_quotation/views/sale_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

<record id="view_sales_order_filter" model="ir.ui.view">
<field name="model">sale.order</field>
<field name="inherit_id" ref="shopinvader.view_sales_order_filter" />
<field name="inherit_id" ref="sale.view_sales_order_filter" />
<field name="arch" type="xml">
<filter name="shopinvader_cart" position="after">
<filter name="activities_upcoming_all" position="after">
<filter
string="Shopinvader Quotations"
name="shopinvader_quotation"
domain="[('typology', '=', 'quotation'), ('shopinvader_backend_id', '!=', False)]"
domain="[('typology', '=', 'quotation')]"
/>
</filter>
</field>
Expand All @@ -25,21 +25,21 @@
<field name="type">ir.actions.act_window</field>
<field name="res_model">sale.order</field>
<field name="view_mode">tree,kanban,form,calendar,pivot,graph,activity</field>
<field name="view_id" ref="shopinvader.view_shop_quotation_tree" />
<field name="view_id" ref="sale.view_quotation_tree" />
<field
name="search_view_id"
ref="sale.sale_order_view_search_inherit_quotation"
/>
<field name="context">{"default_typology": "quotation"}</field>
<field name="domain">
[("typology", "=", "quotation"), ("shopinvader_backend_id", "!=", False)]
[("typology", "=", "quotation")]
</field>
</record>

<menuitem
action="action_quotations"
id="menu_quotations"
parent="shopinvader.menu_shopinvader_orders"
parent="sale.sale_order_menu"
sequence="15"
/>

Expand Down

0 comments on commit e667997

Please sign in to comment.