Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syncing from upstream OCA/sale-workflow (14.0) #1842

Merged
merged 74 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
4ad4208
Added translation using Weblate (Spanish)
Ivorra78 Jan 16, 2024
e621f72
Added translation using Weblate (Spanish)
Ivorra78 Jan 16, 2024
f9ffe75
Added translation using Weblate (Spanish)
Ivorra78 Jan 16, 2024
9077ea9
Added translation using Weblate (Spanish)
Ivorra78 Jan 16, 2024
65aca5f
Added translation using Weblate (Spanish)
Ivorra78 Jan 16, 2024
f4b5eb4
Added translation using Weblate (Spanish)
Ivorra78 Jan 16, 2024
9255026
Added translation using Weblate (Spanish)
Ivorra78 Jan 16, 2024
889c2c0
Added translation using Weblate (Spanish)
Ivorra78 Jan 16, 2024
8f843ce
Added translation using Weblate (Spanish)
Ivorra78 Jan 16, 2024
7f18dac
Added translation using Weblate (Spanish)
Ivorra78 Jan 16, 2024
a78736b
Added translation using Weblate (Spanish)
Ivorra78 Jan 16, 2024
c6bf4d2
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
fab3873
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
a9818f8
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
563bf2b
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
b22b989
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
41e8c63
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
8b03c74
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
72f181f
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
8848bae
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
c4a81fd
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
bd5ede1
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
0f1b283
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
5738f7e
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
3b86567
Added translation using Weblate (Spanish)
Ivorra78 Jan 16, 2024
c77676f
Added translation using Weblate (Spanish)
Ivorra78 Jan 16, 2024
7111059
Added translation using Weblate (Spanish)
Ivorra78 Jan 16, 2024
12d2ae6
Added translation using Weblate (Spanish)
Ivorra78 Jan 16, 2024
d10773a
Added translation using Weblate (Spanish)
Ivorra78 Jan 16, 2024
c248de6
Added translation using Weblate (Spanish)
Ivorra78 Jan 16, 2024
6f6f1b2
Added translation using Weblate (Spanish)
Ivorra78 Jan 16, 2024
049d39f
Added translation using Weblate (Spanish)
Ivorra78 Jan 16, 2024
2a6b72b
Added translation using Weblate (Spanish)
Ivorra78 Jan 16, 2024
84e02bd
Added translation using Weblate (Spanish)
Ivorra78 Jan 16, 2024
0ffeeba
Added translation using Weblate (Spanish)
Ivorra78 Jan 16, 2024
2d5aef3
Added translation using Weblate (Spanish)
Ivorra78 Jan 16, 2024
3963ce6
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
6e5bc37
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
b8c7e76
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
182a8b9
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
6976284
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
1b7332e
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
7b67933
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
0467778
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
90dbb75
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
6cc3feb
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
0b81351
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
70dd81a
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
93015a8
Translated using Weblate (Spanish)
Ivorra78 Jan 16, 2024
46d1a93
Added translation using Weblate (Spanish)
Ivorra78 Jan 17, 2024
7462dbf
Added translation using Weblate (Spanish)
Ivorra78 Jan 17, 2024
410ac6a
Added translation using Weblate (Spanish)
Ivorra78 Jan 17, 2024
b168a34
Added translation using Weblate (Spanish)
Ivorra78 Jan 17, 2024
f1b5fd8
Added translation using Weblate (Spanish)
Ivorra78 Jan 17, 2024
b9be7d3
Added translation using Weblate (Spanish)
Ivorra78 Jan 17, 2024
237c8f1
pricelist_cache: fix concurrent access errors
mmequignon Nov 17, 2023
5f73e37
pricelist_cache: Avoid long sql transactions
mmequignon Nov 17, 2023
424454d
Added translation using Weblate (Spanish)
Ivorra78 Jan 17, 2024
d1a98a3
Merge PR #2783 into 14.0
OCA-git-bot Jan 17, 2024
76f49ad
[BOT] post-merge updates
OCA-git-bot Jan 17, 2024
e93aa33
Translated using Weblate (Spanish)
Ivorra78 Jan 17, 2024
b2ca5b5
Translated using Weblate (Spanish)
Ivorra78 Jan 17, 2024
7a39dda
Translated using Weblate (Spanish)
Ivorra78 Jan 17, 2024
281684c
Translated using Weblate (Spanish)
Ivorra78 Jan 17, 2024
ca09369
Translated using Weblate (Spanish)
Ivorra78 Jan 17, 2024
cda2f41
Translated using Weblate (Spanish)
Ivorra78 Jan 17, 2024
e0d6fdf
Translated using Weblate (Spanish)
Ivorra78 Jan 17, 2024
eb0e9fc
Translated using Weblate (Spanish)
Ivorra78 Jan 17, 2024
189354d
Added translation using Weblate (Spanish)
Ivorra78 Jan 17, 2024
c6cf040
Added translation using Weblate (Spanish)
Ivorra78 Jan 17, 2024
2292f6e
Added translation using Weblate (Spanish)
Ivorra78 Jan 17, 2024
f188616
Translated using Weblate (Spanish)
Ivorra78 Jan 17, 2024
d3fdf63
Translated using Weblate (Spanish)
Ivorra78 Jan 17, 2024
bdc9ed2
Translated using Weblate (Spanish)
Ivorra78 Jan 17, 2024
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Available addons
addon | version | maintainers | summary
--- | --- | --- | ---
[portal_sale_personal_data_only](portal_sale_personal_data_only/) | 14.0.1.0.0 | | Portal Sale Personal Data Only
[pricelist_cache](pricelist_cache/) | 14.0.1.3.1 | | Provide a new model to cache price lists and update it, to make it easier to retrieve them.
[pricelist_cache](pricelist_cache/) | 14.0.1.4.0 | | Provide a new model to cache price lists and update it, to make it easier to retrieve them.
[pricelist_cache_rest](pricelist_cache_rest/) | 14.0.1.0.0 | | Provides an endpoint to get product prices for a given customer
[product_form_sale_link](product_form_sale_link/) | 14.0.1.1.1 | | Adds a button on product forms to access Sale Lines
[product_supplierinfo_for_customer_elaboration](product_supplierinfo_for_customer_elaboration/) | 14.0.1.0.0 | | Allows to define default elaborations and elaboration notes on product customerinfos
Expand Down
8 changes: 7 additions & 1 deletion pricelist_cache/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Pricelist Cache
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:1645a3edec38192f6cbbb122c808436def3011a9403b4f81cb154b79f705a018
!! source digest: sha256:b0c1ec69f53e119390520037e3d2bbf2eb05a887f70f491a1413c23076d6d480
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -45,6 +45,12 @@ However, new prices will be cached in the following cases:
.. contents::
:local:

Known issues / Roadmap
======================

* Use job dependencies.
If pricelist a is based on b, then job a should depend on job b.

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

Expand Down
2 changes: 1 addition & 1 deletion pricelist_cache/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Provide a new model to cache price lists and update it,
to make it easier to retrieve them.
""",
"version": "14.0.1.3.1",
"version": "14.0.1.4.0",
"category": "Hidden",
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
Expand Down
43 changes: 26 additions & 17 deletions pricelist_cache/models/product_pricelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Pricelist(models.Model):
)
is_pricelist_cache_computed = fields.Boolean()
is_pricelist_cache_available = fields.Boolean(
compute="_compute_is_pricelist_cache_available", store=True
compute="_compute_is_pricelist_cache_available"
)

@api.depends(
Expand All @@ -29,23 +29,30 @@ def _compute_parent_pricelist_ids(self):
for record in self:
record.parent_pricelist_ids = record._get_parent_pricelists()

@api.depends(
"is_pricelist_cache_computed",
"item_ids",
"item_ids.applied_on",
"item_ids.base",
"item_ids.base_pricelist_id",
"item_ids.base_pricelist_id.is_pricelist_cache_available",
)
def _compute_is_pricelist_cache_available(self):
# TODO This might be slow, if pricelist tree is deep.
for record in self:
record.is_pricelist_cache_available = (
record.is_pricelist_cache_computed
and all(
record.parent_pricelist_ids.mapped("is_pricelist_cache_available")
)
parents = record._get_parent_list_tree()
record.is_pricelist_cache_available = all(
parents.mapped("is_pricelist_cache_computed")
)

def _get_parent_list_tree(self):
self.ensure_one()
query = """
WITH RECURSIVE parent_pricelist AS (
SELECT id
FROM product_pricelist
WHERE id = %(pricelist_id)s
UNION SELECT item.base_pricelist_id AS id
FROM product_pricelist_item item
INNER JOIN parent_pricelist parent
ON item.pricelist_id = parent.id
)
SELECT id FROM parent_pricelist;
"""
self.flush()
self.env.cr.execute(query, {"pricelist_id": self.id})
return self.search([("id", "in", [row[0] for row in self.env.cr.fetchall()])])

@api.model_create_multi
def create(self, vals_list):
Expand Down Expand Up @@ -87,7 +94,8 @@ def _get_root_pricelist_ids(self):
base_pricelist_id IS NOT NULL
AND base = 'pricelist'
)
);
)
AND active = TRUE;
"""
self.flush()
self.env.cr.execute(no_parent_query)
Expand All @@ -113,7 +121,8 @@ def _get_factor_pricelist_ids(self):
OR price_surcharge != 0.0
)
)
);
)
AND active = TRUE;
"""
self.flush()
self.env.cr.execute(factor_pricelist_query)
Expand Down
17 changes: 15 additions & 2 deletions pricelist_cache/models/product_pricelist_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,21 @@ def _update_pricelist_items_cache(self, pricelist_items):

def create_full_cache(self):
"""Creates cache for all prices applied to all pricelists."""
pricelists = self.env["product.pricelist"].search([])
pricelist_ids = pricelists.ids
pricelist_model = self.env["product.pricelist"]
# Here, we split price computation in 2.
# Huge pricelists (root pricelists and factor pricelists) are computed
# on their own, in order to avoid long sql transactions.pricelist_model
# Smaller pricelists can be computed 3 by 3, since they are taking
# less time to process.
global_list_ids = pricelist_model._get_global_pricelist_ids()
# Belt and braces. Just to ensure higher level lists are executed first
global_list_ids.sort()
for list_id in global_list_ids:
self.with_delay().update_product_pricelist_cache(pricelist_ids=[list_id])
regular_list_ids = self.env["product.pricelist"].search(
[("id", "not in", global_list_ids)]
)
pricelist_ids = regular_list_ids.ids
# Spawn a job every 3 pricelists (reduce the number of jobs created)
for chunk_ids in tools.misc.split_every(3, pricelist_ids):
self.with_delay().update_product_pricelist_cache(pricelist_ids=chunk_ids)
Expand Down
2 changes: 2 additions & 0 deletions pricelist_cache/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Use job dependencies.
If pricelist a is based on b, then job a should depend on job b.
35 changes: 21 additions & 14 deletions pricelist_cache/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -367,7 +366,7 @@ <h1 class="title">Pricelist Cache</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:1645a3edec38192f6cbbb122c808436def3011a9403b4f81cb154b79f705a018
!! source digest: sha256:b0c1ec69f53e119390520037e3d2bbf2eb05a887f70f491a1413c23076d6d480
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/sale-workflow/tree/14.0/pricelist_cache"><img alt="OCA/sale-workflow" src="https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/sale-workflow-14-0/sale-workflow-14-0-pricelist_cache"><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/sale-workflow&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Provides a cron task who caches prices for all products and all pricelists.
Expand All @@ -383,34 +382,42 @@ <h1 class="title">Pricelist Cache</h1>
<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="#other-credits" id="toc-entry-5">Other credits</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
<li><a class="reference internal" href="#known-issues-roadmap" id="toc-entry-1">Known issues / Roadmap</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="#other-credits" id="toc-entry-6">Other credits</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-7">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#toc-entry-1">Known issues / Roadmap</a></h1>
<ul class="simple">
<li>Use job dependencies.
If pricelist a is based on b, then job a should depend on job b.</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/sale-workflow/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/sale-workflow/issues/new?body=module:%20pricelist_cache%0Aversion:%2014.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>Camptocamp</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>Telmo Santos &lt;<a class="reference external" href="mailto:telmo.santos&#64;camptocamp.com">telmo.santos&#64;camptocamp.com</a>&gt;</li>
<li>Matthieu Méquignon &lt;<a class="reference external" href="mailto:matthieu.mequignon&#64;camptocamp.com">matthieu.mequignon&#64;camptocamp.com</a>&gt;</li>
Expand All @@ -428,15 +435,15 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
</ul>
</div>
<div class="section" id="other-credits">
<h2><a class="toc-backref" href="#toc-entry-5">Other credits</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">Other credits</a></h2>
<p><strong>Financial support</strong></p>
<ul class="simple">
<li>Cosanum</li>
<li>Camptocamp R&amp;D</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-7">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
1 change: 1 addition & 0 deletions pricelist_cache/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import test_pricelist_cache
from . import test_partner_pricelist_cache
from . import test_methods
25 changes: 25 additions & 0 deletions pricelist_cache/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class TestPricelistCacheCommon(SavepointCase):
@classmethod
def setUpClassBaseCache(cls):
cls.cache_model.cron_reset_pricelist_cache()
cls.env["product.pricelist"].invalidate_cache(["is_pricelist_cache_available"])

@classmethod
def set_currency(cls):
Expand Down Expand Up @@ -132,3 +133,27 @@ def setUpClass(cls):
cls.set_currency()
cls.setUpClassBaseCache()
cls.partner = cls.env.ref("base.res_partner_12")

def _flush_cache(self):
self.cache_model.flush_pricelist_cache()
self.env["res.partner"].invalidate_cache(["is_pricelist_cache_available"])
self.env["product.pricelist"].invalidate_cache(["is_pricelist_cache_available"])

def _update_cache(self, pricelist_ids=None, product_ids=None):
self.cache_model.update_product_pricelist_cache(
product_ids=product_ids, pricelist_ids=pricelist_ids
)
self.env["res.partner"].invalidate_cache(["is_pricelist_cache_available"])
self.env["product.pricelist"].invalidate_cache(["is_pricelist_cache_available"])

def assert_cache_available(self, lists):
self.assertTrue(all(lists.mapped("is_pricelist_cache_available")))

def assert_cache_computed(self, lists):
self.assertTrue(all(lists.mapped("is_pricelist_cache_computed")))

def assert_cache_not_available(self, lists):
self.assertFalse(any(lists.mapped("is_pricelist_cache_available")))

def assert_cache_not_computed(self, lists):
self.assertFalse(any(lists.mapped("is_pricelist_cache_computed")))
38 changes: 38 additions & 0 deletions pricelist_cache/tests/test_methods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2023 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from .common import TestPricelistCacheCommon


class TestPricelistCacheModels(TestPricelistCacheCommon):
def test_get_parent_lists_tree(self):
list0 = self.list0
list1 = self.list1
list2 = self.list2
list3 = self.list3
list4 = self.list4
list5 = self.list5
# list0 has no parent list, its tree should be itself only
list0_parents_tree = list0._get_parent_list_tree()
expected_list0_tree = list0
self.assertEqual(list0_parents_tree, expected_list0_tree)
# list1 parent is list0, tree should be list0|list1
list1_parents_tree = list1._get_parent_list_tree()
expected_list1_tree = expected_list0_tree | list1
self.assertEqual(list1_parents_tree, expected_list1_tree)
# list2 parent is list1, tree should be list0|list1|list2
list2_parents_tree = list2._get_parent_list_tree()
expected_list2_tree = expected_list1_tree | list2
self.assertEqual(list2_parents_tree, expected_list2_tree)
# list3 parent is list2, tree should be list0|list1|list2|list3
list3_parents_tree = list3._get_parent_list_tree()
expected_list3_tree = expected_list2_tree | list3
self.assertEqual(list3_parents_tree, expected_list3_tree)
# list4 parent is list0, tree should be list0|list4
list4_parents_tree = list4._get_parent_list_tree()
expected_list4_tree = expected_list0_tree | list4
self.assertEqual(list4_parents_tree, expected_list4_tree)
# list 5 parent is list3, tree should be list0|list1|list2|list3|list5
list5_parents_tree = list5._get_parent_list_tree()
expected_list5_tree = expected_list3_tree | list5
self.assertEqual(list5_parents_tree, expected_list5_tree)
24 changes: 4 additions & 20 deletions pricelist_cache/tests/test_partner_pricelist_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,6 @@ def test_partner_pricelists(self):
result.sort(key=lambda r: r["id"])
self.assertEqual(result, expected_result)

def _flush_cache(self):
self.cache_model.flush_pricelist_cache()

def assert_cache_available(self, lists):
self.assertTrue(all(lists.mapped("is_pricelist_cache_available")))

def assert_cache_computed(self, lists):
self.assertTrue(all(lists.mapped("is_pricelist_cache_computed")))

def assert_cache_not_available(self, lists):
self.assertFalse(any(lists.mapped("is_pricelist_cache_available")))

def assert_cache_not_computed(self, lists):
self.assertFalse(any(lists.mapped("is_pricelist_cache_computed")))

def assert_partner_cache_not_available(self):
regex = r"Pricelist caching in progress. Retry later"
with self.assertRaisesRegex(UserError, regex):
Expand All @@ -47,7 +32,6 @@ def assert_partner_cache_available(self):
self.partner._pricelist_cache_get_prices()

def test_partner_inconsistent_cache(self):
cache_model = self.cache_model.with_context(debug_test=True)
# Initialize
partner = self.partner
list3 = self.list3
Expand All @@ -71,7 +55,7 @@ def test_partner_inconsistent_cache(self):
# Computation
# - list0, list1, list3 -> False
# - list2 -> True
cache_model.update_product_pricelist_cache(pricelist_ids=list2.ids)
self._update_cache(pricelist_ids=list2.ids)
self.assert_cache_computed(list2)
self.assert_cache_not_computed(list3 | list1 | list0)
# No cache is available, because list2 depends on pricelists that
Expand All @@ -86,7 +70,7 @@ def test_partner_inconsistent_cache(self):
# Computation
# - list0, list3 -> False
# - list1, list2 -> True
cache_model.update_product_pricelist_cache(pricelist_ids=list1.ids)
self._update_cache(pricelist_ids=list1.ids)
self.assert_cache_computed(list2 | list1)
self.assert_cache_not_computed(list3 | list0)
# No cache is available, because list1 and list2 depends on list0 that
Expand All @@ -102,7 +86,7 @@ def test_partner_inconsistent_cache(self):
# Computation
# - list0, list1, list2 -> True
# - list3 -> False
cache_model.update_product_pricelist_cache(pricelist_ids=list0.ids)
self._update_cache(pricelist_ids=list0.ids)
self.assert_cache_computed(list0 | list1 | list2)
self.assert_cache_not_computed(list3)
# Now, all list0-2 are available, because none of them have a parent pricelist
Expand All @@ -118,7 +102,7 @@ def test_partner_inconsistent_cache(self):
# - all_lists -> True
# Computation
# - all_lists -> True
cache_model.update_product_pricelist_cache(pricelist_ids=list3.ids)
self._update_cache(pricelist_ids=list3.ids)
self.assert_cache_available(all_lists)
self.assert_cache_computed(all_lists)
self.assert_partner_cache_available()
Loading
Loading