Skip to content

Commit

Permalink
add cron to check for expired primeships
Browse files Browse the repository at this point in the history
  • Loading branch information
nayatec committed Nov 27, 2023
1 parent abdf73a commit f2790aa
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions sale_partner_primeship/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Contributors
* `Akretion <https://www.akretion.com>`_:

* Florian Mounier
* Olivier Nibart

Maintainers
~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions sale_partner_primeship/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"views/res_partner_views.xml",
"security/ir.model.access.csv",
"security/sale_partner_primeship.xml",
"data/ir_cron.xml",
],
"license": "LGPL-3",
}
16 changes: 16 additions & 0 deletions sale_partner_primeship/data/ir_cron.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record forcecreate="True" id="ir_cron_check_primeship_expired" model="ir.cron">
<field name="name">Check for Expired Partner Primeships</field>
<field ref="model_res_partner" name="model_id" />
<field name="state">code</field>
<field name="code">model._check_expired_primeships()</field>
<field eval="True" name="active" />
<field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field eval="True" name="doall" />
<field name="nextcall" eval="(DateTime.now()).strftime('%Y-%m-%d 00:00:00')" />
</record>
</odoo>
6 changes: 6 additions & 0 deletions sale_partner_primeship/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ def _compute_active_primeship(self):
def _compute_primeship_count(self):
for record in self:
record.primeship_count = len(record.commercial_partner_id.primeship_ids)

@api.model
def _check_expired_primeships(self):
self.with_context(
active_test=False,
).search([("active_primeship", "=", True)])._compute_active_primeship()

0 comments on commit f2790aa

Please sign in to comment.