تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
210 أدوات العرض

ODOO 18 enterprise. 

When ODOO issues a document from the pos or an invoice, it automatically generates a loyalty card, giving the client the points expected according to the reward program set by the ODOO administrator.

I want to give these points to some customers only.

For this purpose, I added a checkbox in the res.partner model. If checked, give the points; otherwise, don't do it.

I created an automated action that, through the domain, selects the clients with the box unchecked and deletes the corresponding records in the loyalty cards table through the execution of a fragment of python code.

I tried several different codes without success.

Can anybody help me out?





الصورة الرمزية
إهمال

"Loyalty Cards" is not a question. A question is a substantial phrase that ends with "?"

We get close to 1,000 posts a month and not everyone will open a post to find out what your question is.

I have edited your post to make the title a question.

In the future, please consider (1) using a Question that makes it clear what you ask without requiring people to open your post and (2) adding Tags. This will often increase the chances people will respond and also make everything clearer for others who may come along later searching for the same thing.

Failing that, you can paste your future posts into an AI Chatbot and ask it to "please generate a question of no more than 16 words that summarizes what I am asking" and use that as your question.

See also https://www.odoo.com/forum/help-1/meta-why-do-some-questions-get-answers-and-others-do-not-25620

الكاتب

Thank you very much for your help.

الكاتب أفضل إجابة

Thank you for your help. Unfortunately, I do not have access to the ODOO code, so I wonder if there is a solution working through an automated action.

الصورة الرمزية
إهمال
أفضل إجابة

Hi,

Please refer to the code below:

Partner


class ResPartner(models.Model):

    _inherit = "res.partner"


    enable_loyalty = fields.Boolean("Eligible for Loyalty Program")


Warning:


from odoo import models, _

from odoo.exceptions import UserError


class LoyaltyCard(models.Model):

    _inherit = "loyalty.card"


    def create(self, vals):

        partner_id = vals.get("partner_id")

        if partner_id:

            partner = self.env["res.partner"].browse(partner_id)

            if not partner.enable_loyalty:

                raise UserError(_("This customer is not eligible for loyalty cards."))

        return super().create(vals)


Solved forum:

1. https://www.odoo.com/id_ID/forum/help-1/apply-loyalty-program-to-certain-customers-277435


Hope it helps.

الصورة الرمزية
إهمال