Skip to content

Commit

Permalink
Merge PR #3122 into 15.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed May 12, 2024
2 parents 72ce6f6 + fde9448 commit 756eb62
Show file tree
Hide file tree
Showing 37 changed files with 3,184 additions and 0 deletions.
106 changes: 106 additions & 0 deletions pricelist_cache/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
===============
Pricelist Cache
===============

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:0477b5e81a08a349e1800527bac604a66f865d14f4b14b0076943d4cbc53aaf1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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%2Fsale--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/sale-workflow/tree/15.0/pricelist_cache
:alt: OCA/sale-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-workflow-15-0/sale-workflow-15-0-pricelist_cache
: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/sale-workflow&target_branch=15.0
:alt: Try me on Runboat

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

Provides a cron task who caches prices for all products and all pricelists.
The goal is to be able to generate a whole catalog of prices and products for a given customer in a decent time.

Everyday, the cron task will trash the previous day's cache, and rebuild it from scratch.
It means that at any moment, the prices stored in the cache are those of the current day, and will not be recomputed before the next day.

However, new prices will be cached in the following cases:

* new product is created
* new pricelist is created
* new pricelist item is created

**Table of contents**

.. 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
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/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/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**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Camptocamp

Contributors
~~~~~~~~~~~~

* Telmo Santos <[email protected]>
* Matthieu Méquignon <[email protected]>
* Simone Orsi <[email protected]>
* Thierry Ducrest <[email protected]>
* Sébastien Alix <[email protected]>
* `Trobz <https://trobz.com>`_:
* Hai Lang <[email protected]>

Other credits
~~~~~~~~~~~~~

**Financial support**

* Cosanum
* Camptocamp R&D

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.

This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/15.0/pricelist_cache>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions pricelist_cache/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import models
from . import wizards
from .hooks import set_default_partner_product_filter
37 changes: 37 additions & 0 deletions pricelist_cache/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2021 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Pricelist Cache",
"summary": """
Provide a new model to cache price lists and update it,
to make it easier to retrieve them.
""",
"version": "15.0.1.4.1",
"category": "Hidden",
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": [
"partner_pricelist_search",
"base_automation",
"product",
"sale",
"queue_job",
],
"website": "https://github.com/OCA/sale-workflow",
"data": [
"security/ir.model.access.csv",
"data/base_automation.xml",
"data/ir_cron.xml",
"data/ir_filters_data.xml",
"data/queue_job.xml",
"views/res_partner.xml",
"views/product_pricelist.xml",
"views/product_pricelist_cache.xml",
"wizards/pricelist_cache_wizard.xml",
],
"demo": [
"data/demo.xml",
],
"installable": True,
"post_init_hook": "set_default_partner_product_filter",
}
39 changes: 39 additions & 0 deletions pricelist_cache/data/base_automation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" ?>
<odoo>
<!-- TODO: drop this dependency and make the trigger configurable
via an ir_config_param -->
<record id="automation_update_product_pricelist_cache" model="base.automation">
<field name="name">Update Product Pricelist Cache</field>
<field name="model_id" ref="product.model_product_pricelist_item" />
<field name="state">code</field>
<field name="active" eval="True" />
<field name="code">record.update_product_pricelist_cache()</field>
<field name="trigger">on_create</field>
<field
name="trigger_field_ids"
eval="[(6, 0, [
ref('product.field_product_pricelist_item__active'),
ref('product.field_product_pricelist_item__applied_on'),
ref('product.field_product_pricelist_item__base'),
ref('product.field_product_pricelist_item__base_pricelist_id'),
ref('product.field_product_pricelist_item__categ_id'),
ref('product.field_product_pricelist_item__company_id'),
ref('product.field_product_pricelist_item__compute_price'),
ref('product.field_product_pricelist_item__currency_id'),
ref('product.field_product_pricelist_item__date_end'),
ref('product.field_product_pricelist_item__date_start'),
ref('product.field_product_pricelist_item__fixed_price'),
ref('product.field_product_pricelist_item__min_quantity'),
ref('product.field_product_pricelist_item__percent_price'),
ref('product.field_product_pricelist_item__price_discount'),
ref('product.field_product_pricelist_item__price_max_margin'),
ref('product.field_product_pricelist_item__price_min_margin'),
ref('product.field_product_pricelist_item__price_round'),
ref('product.field_product_pricelist_item__price_surcharge'),
ref('product.field_product_pricelist_item__pricelist_id'),
ref('product.field_product_pricelist_item__product_id'),
ref('product.field_product_pricelist_item__product_tmpl_id'),
])]"
/>
</record>
</odoo>
140 changes: 140 additions & 0 deletions pricelist_cache/data/demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<!--root pricelist 0-->

<record id="list0" model="product.pricelist">
<field name="name">Pricelist 0</field>
</record>

<record id="item2" model="product.pricelist.item">
<field name="base">list_price</field>
<field name="applied_on">0_product_variant</field>
<field name="pricelist_id" ref="list0" />
<field name="product_id" ref="product.product_product_6" />
<field name="fixed_price">100.0</field>
</record>

<record id="item3" model="product.pricelist.item">
<field name="base">list_price</field>
<field name="applied_on">0_product_variant</field>
<field name="pricelist_id" ref="list0" />
<field name="product_id" ref="product.product_product_8" />
<field name="fixed_price">100.0</field>
</record>


<!--child pricelist 1, based on pricelist 0-->
<record id="list1" model="product.pricelist">
<field name="name">Pricelist 1</field>
<field name="sequence">2</field>
</record>

<record id="item4" model="product.pricelist.item">
<field name="pricelist_id" ref="list1" />
<field name="applied_on">3_global</field>
<field name="compute_price">formula</field>
<field name="base">pricelist</field>
<field name="base_pricelist_id" ref="list0" />
</record>

<record id="item5" model="product.pricelist.item">
<field name="pricelist_id" ref="list1" />
<field name="applied_on">0_product_variant</field>
<field name="base">list_price</field>
<field name="product_id" ref="product.product_product_6" />
<field name="fixed_price">75.0</field>
</record>

<!--child pricelist 2, based on pricelist 1-->
<record id="list2" model="product.pricelist">
<field name="name">Pricelist 2</field>
<field name="sequence">3</field>
</record>

<record id="item6" model="product.pricelist.item">
<field name="pricelist_id" ref="list2" />
<field name="applied_on">3_global</field>
<field name="compute_price">formula</field>
<field name="base">pricelist</field>
<field name="base_pricelist_id" ref="list1" />
</record>

<record id="item7" model="product.pricelist.item">
<field name="base">list_price</field>
<field name="applied_on">0_product_variant</field>
<field name="pricelist_id" ref="list2" />
<field name="product_id" ref="product.product_product_6" />
<field name="fixed_price">50.0</field>
<field name="date_start">2021-03-01</field>
<field name="date_end">2021-04-01</field>
</record>

<!--child pricelist 3, based on pricelist 2-->
<record id="list3" model="product.pricelist">
<field name="name">Pricelist 3</field>
<field name="sequence">4</field>
</record>

<record id="item8" model="product.pricelist.item">
<field name="pricelist_id" ref="list3" />
<field name="applied_on">3_global</field>
<field name="compute_price">formula</field>
<field name="base">pricelist</field>
<field name="base_pricelist_id" ref="list2" />
</record>

<record id="item9" model="product.pricelist.item">
<field name="base">list_price</field>
<field name="applied_on">0_product_variant</field>
<field name="pricelist_id" ref="list3" />
<field name="product_id" ref="product.product_product_6" />
<field name="fixed_price">25.0</field>
</record>

<!--root pricelist 4, based on list0-->
<record id="list4" model="product.pricelist">
<field name="name">Pricelist 4</field>
<field name="sequence">5</field>
</record>

<record id="item10" model="product.pricelist.item">
<field name="pricelist_id" ref="list4" />
<field name="applied_on">3_global</field>
<field name="compute_price">formula</field>
<field name="base">pricelist</field>
<field name="base_pricelist_id" ref="list0" />
</record>

<record id="item11" model="product.pricelist.item">
<field name="base">list_price</field>
<field name="applied_on">0_product_variant</field>
<field name="pricelist_id" ref="list4" />
<field name="product_id" ref="product.product_product_6" />
<field name="fixed_price">15.0</field>
</record>

<record id="item12" model="product.pricelist.item">
<field name="base">list_price</field>
<field name="applied_on">0_product_variant</field>
<field name="pricelist_id" ref="list4" />
<field name="product_id" ref="product.product_product_7" />
<field name="fixed_price">50</field>
</record>

<!-- factor pricelist 5, based on pricelist 3-->
<record id="list5" model="product.pricelist">
<field name="name">Pricelist 5</field>
<field name="sequence">6</field>
</record>

<record id="item13" model="product.pricelist.item">
<field name="pricelist_id" ref="list5" />
<field name="applied_on">3_global</field>
<field name="compute_price">formula</field>
<field name="base">pricelist</field>
<field name="base_pricelist_id" ref="list3" />
<field name="price_surcharge">20</field>
</record>

</odoo>
21 changes: 21 additions & 0 deletions pricelist_cache/data/ir_cron.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2020 Camptocamp SA
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo noupdate="1">

<record model="ir.cron" id="cron_reset_pricelist_cache">
<field name='name'>Reset pricelist cache</field>
<field name='interval_number'>1</field>
<field name='interval_type'>days</field>
<field name="numbercall">-1</field>
<field name="active" eval="False" />
<field name="model_id" ref="pricelist_cache.model_product_pricelist_cache" />
<field name="state">code</field>
<field name="code">model.cron_reset_pricelist_cache()</field>
<field
name="nextcall"
eval="(DateTime.now().replace(hour=1, minute=0) + timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')"
/>
</record>

</odoo>
9 changes: 9 additions & 0 deletions pricelist_cache/data/ir_filters_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="product_filter_default" model="ir.filters">
<field name="name">Pricelist cache default product filter for partner</field>
<field name="model_id">product.product</field>
<field name="domain" eval="[('sale_ok', '=', True)]" />
<field name="user_id" eval="False" />
</record>
</odoo>
15 changes: 15 additions & 0 deletions pricelist_cache/data/queue_job.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2021 Camptocamp SA
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo noupdate="1">
<record id="channel_pricelist_cache" model="queue.job.channel">
<field name="name">pricelist_cache</field>
<field name="parent_id" ref="queue_job.channel_root" />
</record>

<record id="job_function_pricelist_cache_update" model="queue.job.function">
<field name="model_id" ref="pricelist_cache.model_product_pricelist_cache" />
<field name="method">update_product_pricelist_cache</field>
<field name="channel_id" ref="channel_pricelist_cache" />
</record>
</odoo>
Loading

0 comments on commit 756eb62

Please sign in to comment.