Skip to Content
Menu
This question has been flagged

Hi, I started a few weeks ago with odoo 9 and now, I'm building a module that inherit from point of sales : A loyalty module. One of the things I want to realize is a reduction coupon system (physical tickets with a code that is entered in the sale interface and recognized as a determined amount of reduction).

So, the class of coupons is :

class loyalty_coupon(osv.osv):
    _name = 'loyalty.coupon'
    _columns = {
        'name':                 fields.char('Name', size=32, select=1, required=True, help='An internal identification for this loyalty coupon'),
        'loyalty_program_id':   fields.many2one('loyalty.program', 'Loyalty Program', help='The Loyalty Program this coupon belongs to'),
        'reduction':       fields.float('Reduction', help='The amount of reduction of this coupon in EUR'),
        'date':                 fields.date('Date Limit', help='The date limit of the coupon'),
        'used':           fields.boolean('Used',        help='The state of the coupon, used or not used'),
        'commande':         fields.many2one('pos.order', 'Order', help="If used, it's the order this coupon belongs to"),
    }

    _defaults = {
        'used': False,
        'date': datetime.date.today(),
    }

But my problem is in the sale interface where I use this function :

var _super = models.Order;
models.Order = models.Order.extend({
...
    apply_coupon: function(coupon){
...
        for (var i = 0; i < this.pos.loyalty.coupons.length; i++) {
            if (coupon.reduction === this.pos.loyalty.coupons[i].reduction && coupon.name === this.pos.loyalty.coupons[i].name) {
                this.pos.loyalty.coupons[i].used = true;
            }
        }
...
     }
...
}

In the interface, the coupon "used" attribute is right passed to true where the coupon is used.

But, when I'm looking to views or the database or also when I refresh the page, the coupon is unused ('used' = false).

I did lots of research and I understood that I need to synchronize datas in the interface with real datas in the database. The problem is that I don't know how to do this.

Sorry for potentials mistakes in English and thank you in advance for your help !

Matthieu.

Avatar
Discard
Author Best Answer

Ok I've seen that with openerp 7, we could use the function fetch to access database :

fetch: function(model, fields, domain, ctx){

return new instance.web.Model(model).query(fields).filter(domain).context(ctx).all()

},

But my js file start with :

odoo.define('pos_loyalty.pos_loyalty', function (require) {

"use strict";

As a consequence, instance is not defined and I can't use fetch.


Is there any equivalent for Odoo 9 ?

Maybe, this could be the solution I'm searching ?

Avatar
Discard
Related Posts Replies Views Activity
1
Mar 24
502
0
May 23
833
1
Feb 23
862
1
Dec 22
9695
6
Jun 15
6579