~julie-w/unifield-wm/UTP-925

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
-
  I will create a rule for Purchase Order object
-
  !python {model: audittrail.rule}: |
    name = 'Purchase Order'
    object_ids = self.pool.get('ir.model').search(cr, uid, [('model', '=', 'purchase.order')], context=context)
    rule_id = self.search(cr, uid, [('object_id', 'in', object_ids)], context=context)
    if object_ids and not rule_id:
      # Create the rule
      fields = ['arrival_date', 'date_approve', 'date_order', 'delivery_confirmed_date',
                'delivery_requested_date', 'est_transport_lead_time', 'invoice_method', 'invoice_ids',
                'loan_duration', 'loan_id', 'location_id', 'notes', 'order_type',
                'picking_ids', 'priority', 'ready_to_ship_date', 'rfq_ok', 'shipment_date', 'shipped',
                'state', 'tender_id', 'transport_type', 'valid_till']

      fields_ids = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=' ,'purchase.order'), ('name', 'in', fields)], context=context)
        
      rule_id = self.create(cr, uid, {'name': name,
                                      'object_id': object_ids[0],
                                      'log_write': True,
                                      'log_unlink': True,
                                      'log_create': True,
                                      'field_ids': [(6, 0, fields_ids)],
                                     }, context=context)
                                    
      # Subscribe to the rule
      self.subscribe(cr, uid, rule_id)
-
  I will create a rule for Purchase Order lines
-
  !python {model: audittrail.rule}: |
    name = 'Purchase Order Line'
    object_ids = self.pool.get('ir.model').search(cr, uid, [('model', '=', 'purchase.order.line')], context=context)
    rule_id = self.search(cr, uid, [('object_id', 'in', object_ids)], context=context)
    if object_ids and not rule_id:
      # Create the rule
      fields = ['comment', 'confirmed_delivery_date', 'date_planned', 'default_code',
                'default_name', 'name', 'nomen_manda_0', 'nomen_manda_1', 'nomen_manda_2',
                'nomen_manda_3', 'notes', 'price_unit', 'product_qty', 'product_uom',
                'taxes_id']

      fields_ids = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=' ,'purchase.order.line'), ('name', 'in', fields)], context=context)
      field_name = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=', 'purchase.order.line'), ('name', '=', 'line_number')], context=context)
      field_parent = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=', 'purchase.order.line'), ('name', '=', 'order_id')], context=context)
      
      name_id = False
      parent_id = False
      
      if field_parent:
        parent_id = field_parent[0]
        if field_name:
          name_id = field_name[0]
        
      rule_id = self.create(cr, uid, {'name': name,
                                      'object_id': object_ids[0],
                                      'log_write': True,
                                      'log_unlink': True,
                                      'log_create': True,
                                      'field_ids': [(6, 0, fields_ids)],
                                      'parent_field_id': parent_id,
                                      'name_get_field_id': name_id,
                                     }, context=context)
                                    
      # Subscribe to the rule
      self.subscribe(cr, uid, rule_id)