~camptocamp/openobject-addons/trunk-extra-sale-exceptions-2.0

« back to all changes in this revision

Viewing changes to sale_exceptions/sale.py

  • Committer: Guewen Baconnier
  • Date: 2012-02-21 21:28:50 UTC
  • Revision ID: guewen.baconnier@camptocamp.com-20120221212850-ppn7kboeegvq2ftv
[IMP] sale_exceptions: small modifications of views and base data. Code fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
#  - cr: database cursor
55
55
#  - uid: current user id
56
56
#  - context: current context
57
 
#
58
 
# You can also call a method on the sale.order object, just put its name. The method must return True or False.
59
57
"""
60
58
    }
61
59
 
122
120
    def _exception_rule_eval_context(self, cr, uid, obj_name, obj, context=None):
123
121
        if context is None:
124
122
            context = {}
 
123
 
125
124
        return {obj_name: obj,
126
 
                'self': obj,
 
125
                'self': self.pool.get(obj._name),
127
126
                'object': obj,
128
127
                'obj': obj,
129
128
                'pool': self.pool,
 
129
                'cr': cr,
130
130
                'uid': uid,
131
131
                'user': self.pool.get('res.users').browse(cr, uid, uid),
132
132
                'time': time,
133
133
                # copy context to prevent side-effects of eval
134
 
                'context': context.copy(),}
 
134
                'context': dict(context),}
135
135
 
136
136
    def _rule_eval(self, cr, uid, rule, obj_name, obj, context):
137
137
        expr = rule.code
153
153
 
154
154
        for order_line in order.order_line:
155
155
            for rule in line_exceptions:
 
156
                if rule.id in exception_ids:
 
157
                    continue  # we do not matter if the exception as already been
 
158
                    # found for an order line of this order
156
159
                if self._rule_eval(cr, uid, rule, 'line', order_line, context):
157
160
                    exception_ids.append(rule.id)
158
161
 
159
162
        return exception_ids
160
163
 
161
 
    def _detect_invalid_destination(self, cr, uid, order, context=None):
162
 
        carrier_obj = self.pool.get('delivery.carrier')
163
 
        no_delivery_carrier = carrier_obj.search(cr, uid, [('name', '=', 'No Delivery')])
164
 
        if no_delivery_carrier:
165
 
            no_delivery_carrier_grid = carrier_obj.grid_get(cr, uid, no_delivery_carrier, order.partner_shipping_id.id)
166
 
            if no_delivery_carrier_grid:
167
 
                return True
168
 
        return False
169
 
 
170
164
    def copy(self, cr, uid, id, default=None, context=None):
171
165
        if default is None:
172
166
            default = {}