~unifield-team/unifield-wm/us-826

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
-
  For Stock Picking, rule for the CREATE of objects with the list of fields to track
-
  !python {model: audittrail.rule}: |
    name = 'Stock Picking CREATE'
    object_ids = self.pool.get('ir.model').search(cr, uid, [('model', '=', 'stock.picking')], context=context)
    rule_id = self.search(cr, uid, [('name', '=', name)], context=context)
    if object_ids:
        fields = ['name']
        fields_ids = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=' ,'stock.picking'), ('name', 'in', fields)], context=context)
        vals = {'name': name,
                'object_id': object_ids[0],
                'domain_filter': "[('type', '=', 'in')]",
                'log_write': False,
                'log_unlink': False,
                'log_create': True,
                'field_ids': [(6, 0, fields_ids)],
                }
        if not rule_id:
            rule_id = self.create(cr, uid, vals, context=context)
        elif rule_id:
            self.write(cr, uid, rule_id, vals, context=context)
        # Subscribe to the rule
        self.subscribe(cr, uid, rule_id)
-
  For Stock Picking, rule for the DELETE of objects with the list of fields to track
-
  !python {model: audittrail.rule}: |
    name = 'Stock Picking DELETE'
    object_ids = self.pool.get('ir.model').search(cr, uid, [('model', '=', 'stock.picking')], context=context)
    rule_id = self.search(cr, uid, [('name', '=', name)], context=context)
    if object_ids:
        fields = ['name']
        fields_ids = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=' ,'stock.picking'), ('name', 'in', fields)], context=context)
        vals = {'name': name,
                'object_id': object_ids[0],
                'domain_filter': "[('type', '=', 'in')]",
                'log_write': False,
                'log_unlink': True,
                'log_create': False,
                'field_ids': [(6, 0, fields_ids)],
                }
        if not rule_id:
            rule_id = self.create(cr, uid, vals, context=context)
        elif rule_id:
            self.write(cr, uid, rule_id, vals, context=context)
        # Subscribe to the rule
        self.subscribe(cr, uid, rule_id)
-
  For Stock Picking, rule for the WRITE of objects with the list of fields to track
-
  !python {model: audittrail.rule}: |
    name = 'Stock Picking WRITE'
    object_ids = self.pool.get('ir.model').search(cr, uid, [('model', '=', 'stock.picking')], context=context)
    rule_id = self.search(cr, uid, [('name', '=', name)], context=context)
    if object_ids:
        fields = ['partner_id2', 'backorder_id', 'reason_type_id', 'date', 'min_date', 'order_category', 'warehouse_id', 'attach_cert', 'currency_id']
        fields_ids = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=' ,'stock.picking'), ('name', 'in', fields)], context=context)
        vals = {'name': name,
                'object_id': object_ids[0],
                'domain_filter': "[('type', '=', 'in')]",
                'log_write': True,
                'log_unlink': False,
                'log_create': False,
                'field_ids': [(6, 0, fields_ids)],
                }
        if not rule_id:
            rule_id = self.create(cr, uid, vals, context=context)
        elif rule_id:
            self.write(cr, uid, rule_id, vals, context=context)
        # Subscribe to the rule
        self.subscribe(cr, uid, rule_id)
-
  For Stock Picking, rule for the CREATE of objects with the list of fields to track
-
  !python {model: audittrail.rule}: |
    name = 'Stock Moves CREATE'
    object_ids = self.pool.get('ir.model').search(cr, uid, [('model', '=', 'stock.move')], context=context)
    rule_id = self.search(cr, uid, [('name', '=', name)], context=context)
    if object_ids:
        fields = ['name']
        fields_ids = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=' ,'stock.move'), ('name', 'in', fields)], context=context)
        field_name = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=', 'stock.move'), ('name', '=', 'line_number')], context=context)
        field_parent = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=', 'stock.move'), ('name', '=', 'picking_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]
        vals = {'name': name,
                'object_id': object_ids[0],
                'domain_filter': "[('picking_id', '!=', False), ('picking_id.type', '=', 'in')]",
                'log_write': False,
                'log_unlink': False,
                'log_create': True,
                'field_ids': [(6, 0, fields_ids)],
                'parent_field_id': parent_id,
                'name_get_field_id': name_id,
                }
        if not rule_id:
            rule_id = self.create(cr, uid, vals, context=context)
        elif rule_id:
            self.write(cr, uid, rule_id, vals, context=context)
        # Subscribe to the rule
        self.subscribe(cr, uid, rule_id)
-
  For Stock Moves, rule for the DELETE of objects with the list of fields to track
-
  !python {model: audittrail.rule}: |
    name = 'Stock Moves DELETE'
    object_ids = self.pool.get('ir.model').search(cr, uid, [('model', '=', 'stock.move')], context=context)
    rule_id = self.search(cr, uid, [('name', '=', name)], context=context)
    if object_ids:
        fields = ['name']
        fields_ids = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=' ,'stock.move'), ('name', 'in', fields)], context=context)
        field_name = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=', 'stock.move'), ('name', '=', 'line_number')], context=context)
        field_parent = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=', 'stock.move'), ('name', '=', 'picking_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]
        vals = {'name': name,
                'object_id': object_ids[0],
                'domain_filter': "[('picking_id', '!=', False), ('picking_id.type', '=', 'in')]",
                'log_write': False,
                'log_unlink': True,
                'log_create': False,
                'field_ids': [(6, 0, fields_ids)],
                'parent_field_id': parent_id,
                'name_get_field_id': name_id,
                }
        if not rule_id:
            rule_id = self.create(cr, uid, vals, context=context)
        elif rule_id:
            self.write(cr, uid, rule_id, vals, context=context)
        # Subscribe to the rule
        self.subscribe(cr, uid, rule_id)
-
  For Stock Moves, rule for the WRITE of objects with the list of fields to track
-
  !python {model: audittrail.rule}: |
    name = 'Stock Moves WRITE'
    object_ids = self.pool.get('ir.model').search(cr, uid, [('model', '=', 'stock.move')], context=context)
    rule_id = self.search(cr, uid, [('name', '=', name)], context=context)
    if object_ids:
        fields = ['product_id', 'product_qty', 'product_uom', 'asset_id', 'prodlot_id', 'expired_date', 'location_dest_id', 'date', 'state', 'currency_id', 'price_unit']
        fields_ids = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=' ,'stock.move'), ('name', 'in', fields)], context=context)
        field_name = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=', 'stock.move'), ('name', '=', 'line_number')], context=context)
        field_parent = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=', 'stock.move'), ('name', '=', 'picking_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]
        vals = {'name': name,
                'object_id': object_ids[0],
                'domain_filter': "[('picking_id', '!=', False), ('picking_id.type', '=', 'in')]",
                'log_write': True,
                'log_unlink': False,
                'log_create': False,
                'field_ids': [(6, 0, fields_ids)],
                'parent_field_id': parent_id,
                'name_get_field_id': name_id,
                }
        if not rule_id:
            rule_id = self.create(cr, uid, vals, context=context)
        elif rule_id:
            self.write(cr, uid, rule_id, vals, context=context)
        # Subscribe to the rule
        self.subscribe(cr, uid, rule_id)