1

Currently, I am Working on POS Customization. I've done almost but stuck in this issue.

Py File:

class prescription(osv.osv):

     _name = 'res.prescriptions'

     _columns={

         'prescription_id':fields.many2one('res.partner',"customer"),

      }

class prescription_res_partner(osv.osv):

    _inherit = 'res.partner'

    _columns = {

        'prescriptions_ids':   fields.one2many('res.prescriptions','prescription_id','Prescriptions'),

}

What I would like to do, is that when the user select customer in POS, and click on Prescription Button, it shows only prescriptions that are related to particular selected customer.. For now, it displays all prescriptions as I am not able to set correctly the filter domain. Also.....

i've tried to solve my problem using .query(), .filter() in JS. but getting some errors, while if i put static partner_id then it will display prescriptions for given static partner_id. I want to solve this for dynamic partners. it shows only selected partner's prescriptions...!!!

In JS File:

var def = new $.Deferred();

console.log("deffffffffffffff", def);

var fields = _.find(this.models,function(model){ return model.model === 'res.prescriptions'; });

new instance.web.Model('res.prescriptions')

   .query(fields)

   .filter([['prescription_id', '=', 51]]) // Here i pass static partner_id instead of this i want to pass dynamic partner_id

   .limit(1000)

   .all()

   .then(function(prescriptions){

if (self.render_list_prescription(prescriptions)) { // Render selected partner's Prescription

    def.resolve();

    } else {

    def.reject();

    }

    }, function(err,event){ event.preventDefault(); def.reject(); });

return def;

i've spend almost 3 days to overcome this problem but failed to Deliver it. please help me out from this. Again Many Thanks for your help..!!!

  • can you pass a list of related prescriptions of selected customer from python to js when you click on Prescription Button? or get the list of related prescriptions using js ? – Vishal Khichadiya Aug 05 '17 at 06:35

2 Answers2

1

You can try use domain in fields like this :

_columns = {

'prescriptions_ids': fields.one2many('res.prescriptions','prescription_id','Prescriptions', domain="[('prescription_id', '=', 51)]"),
}

change 51 with an other column in relation

Yacine Bs
  • 182
  • 1
  • 13
  • Thanks For Your Answer But i want to pass this filter domain in JS. Addons side it works fine But i want this stuff done in POS, **.filter([['prescription_id', '=', 51]])** // Here i want to pass selected partner's prescription and Its a dynamic Not a Static ID...!!! – AyAz Mansuri Mar 09 '16 at 14:07
  • you change "51" by your fields id for example domain="[('prescription_id', '=', prescription_id)]" – Yacine Bs Mar 10 '16 at 07:39
  • Earlier i said that it works perfectly in addons side no need to pass domain., i want to solve this issue in JS., want to pass this filter domain in JS. – AyAz Mansuri Mar 10 '16 at 07:53
0

You can do it in on_change method.

prescription_ids = # search for prescriptions related to the selected customer  

# self.pool.get('res.prescriptions').search(cr, uid, [('partner_id', '=', YOU SHOULD GET THE CUSTOMER ID)])

res['domain']['prescription_id'] = [('id', 'in', prescription_ids)]

return res
Kenly
  • 24,317
  • 7
  • 44
  • 60
  • Thank You Rawly., Here on_change method is not working becoz i want this stuff in JS.. In POS, List of Customers is there, select particular customer, click on Prescription Button, so it will show all the prescription related to that selected customer..!!! – AyAz Mansuri Mar 09 '16 at 14:15
  • @AyAzMansuri The `on_change` method should be for `prescription_id`, I used the same aproch with my model so it should work. I wish you to find a solution in `JS` – Kenly Mar 09 '16 at 14:28