2
I will create a rule for Purchase Order object
4
!python {model: audittrail.rule}: |
5
name = 'Purchase Order'
6
object_ids = self.pool.get('ir.model').search(cr, uid, [('model', '=', 'purchase.order')], context=context)
7
rule_id = self.search(cr, uid, [('object_id', 'in', object_ids)], context=context)
8
if object_ids and not rule_id:
10
fields = ['arrival_date', 'date_approve', 'date_order', 'delivery_confirmed_date',
11
'delivery_requested_date', 'est_transport_lead_time', 'invoice_method', 'invoice_ids',
12
'loan_duration', 'loan_id', 'location_id', 'notes', 'order_type',
13
'picking_ids', 'priority', 'ready_to_ship_date', 'rfq_ok', 'shipment_date', 'shipped',
14
'state', 'tender_id', 'transport_type', 'valid_till']
16
fields_ids = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=' ,'purchase.order'), ('name', 'in', fields)], context=context)
18
rule_id = self.create(cr, uid, {'name': name,
19
'object_id': object_ids[0],
20
'domain_filter': "[('rfq_ok', '=', False)]",
24
'field_ids': [(6, 0, fields_ids)],
27
# Subscribe to the rule
28
self.subscribe(cr, uid, rule_id)
30
I will create a rule for Purchase Order lines
32
!python {model: audittrail.rule}: |
33
name = 'Purchase Order Line'
34
object_ids = self.pool.get('ir.model').search(cr, uid, [('model', '=', 'purchase.order.line')], context=context)
35
rule_id = self.search(cr, uid, [('object_id', 'in', object_ids)], context=context)
36
if object_ids and not rule_id:
38
fields = ['comment', 'confirmed_delivery_date', 'date_planned', 'default_code',
39
'default_name', 'name', 'nomen_manda_0', 'nomen_manda_1', 'nomen_manda_2',
40
'nomen_manda_3', 'notes', 'price_unit', 'product_qty', 'product_uom',
43
fields_ids = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=' ,'purchase.order.line'), ('name', 'in', fields)], context=context)
44
field_name = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=', 'purchase.order.line'), ('name', '=', 'line_number')], context=context)
45
field_parent = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=', 'purchase.order.line'), ('name', '=', 'order_id')], context=context)
51
parent_id = field_parent[0]
53
name_id = field_name[0]
55
rule_id = self.create(cr, uid, {'name': name,
56
'object_id': object_ids[0],
60
'field_ids': [(6, 0, fields_ids)],
61
'parent_field_id': parent_id,
62
'name_get_field_id': name_id,
65
# Subscribe to the rule
66
self.subscribe(cr, uid, rule_id)
68
I will create a rule for Sale Order object
70
!python {model: audittrail.rule}: |
72
object_ids = self.pool.get('ir.model').search(cr, uid, [('model', '=', 'sale.order')], context=context)
73
rule_id = self.search(cr, uid, [('object_id', 'in', object_ids)], context=context)
74
if object_ids and not rule_id:
76
fields = ['partner_invoice_id', 'partner_shipping_id', 'picking_ids', 'priority', 'procurement_request',
77
'delivery_requested_date', 'delivery_confirmed_date',
78
'project_id', 'ready_to_ship_date', 'receipt_date', 'requested_date', 'requestor',
79
'shipment_date', 'shipped', 'state', 'transport_type', 'warehouse_id']
81
fields_ids = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=' ,'sale.order'), ('name', 'in', fields)], context=context)
83
rule_id = self.create(cr, uid, {'name': name,
84
'object_id': object_ids[0],
88
'field_ids': [(6, 0, fields_ids)],
91
# Subscribe to the rule
92
self.subscribe(cr, uid, rule_id)
94
I will create a rule for Sale Order lines
96
!python {model: audittrail.rule}: |
97
name = 'Sale Order Line'
98
object_ids = self.pool.get('ir.model').search(cr, uid, [('model', '=', 'sale.order.line')], context=context)
99
rule_id = self.search(cr, uid, [('object_id', 'in', object_ids)], context=context)
100
if object_ids and not rule_id:
102
fields = ['comment', 'confirmed_delivery_date', 'date_planned', 'default_code', 'default_name',
103
'delay', 'discount', 'invoiced', 'notes', 'po_cft', 'price_unit', 'product_uom',
104
'product_uom_qty', 'product_uos', 'product_uos_qty', 'state', 'supplier', 'type']
106
fields_ids = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=' ,'sale.order.line'), ('name', 'in', fields)], context=context)
107
field_name = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=', 'sale.order.line'), ('name', '=', 'line_number')], context=context)
108
field_parent = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=', 'sale.order.line'), ('name', '=', 'order_id')], context=context)
114
parent_id = field_parent[0]
116
name_id = field_name[0]
118
rule_id = self.create(cr, uid, {'name': name,
119
'object_id': object_ids[0],
123
'field_ids': [(6, 0, fields_ids)],
124
'parent_field_id': parent_id,
125
'name_get_field_id': name_id,
128
# Subscribe to the rule
129
self.subscribe(cr, uid, rule_id)
131
I will create a rule for Stock Picking object
133
!python {model: audittrail.rule}: |
134
name = 'Stock Picking'
135
object_ids = self.pool.get('ir.model').search(cr, uid, [('model', '=', 'stock.picking')], context=context)
136
rule_id = self.search(cr, uid, [('object_id', 'in', object_ids)], context=context)
137
if object_ids and not rule_id:
139
fields = ['attach_cert', 'backorder_id', 'change_reason', 'converted_to_standard', 'date_done', 'delivered',
140
'first_shipment_packing_id', 'invoice_state', 'location_dest_id', 'max_date', 'min_date', 'name',
141
'note', 'order_category', 'origin', 'overall_qty', 'reason_type_id', 'sale_id', 'state',
142
'transport_order_id', 'warehouse_id']
144
fields_ids = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=' ,'stock.picking'), ('name', 'in', fields)], context=context)
146
rule_id = self.create(cr, uid, {'name': name,
147
'object_id': object_ids[0],
148
'domain_filter': "[('type', '=', 'in')]",
152
'field_ids': [(6, 0, fields_ids)],
155
# Subscribe to the rule
156
self.subscribe(cr, uid, rule_id)
158
I will create a rule for Stock Moves
160
!python {model: audittrail.rule}: |
162
object_ids = self.pool.get('ir.model').search(cr, uid, [('model', '=', 'stock.move')], context=context)
163
rule_id = self.search(cr, uid, [('object_id', 'in', object_ids)], context=context)
164
if object_ids and not rule_id:
166
fields = ['address_id', 'asset_id', 'change_reason', 'comment', 'date', 'date_expected', 'location_dest_id',
167
'location_id', 'move_dest_id', 'name', 'note', 'prodlot_id', 'product_id', 'product_qty', 'product_uom',
168
'reason_type_id', 'state']
170
fields_ids = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=' ,'stock.move'), ('name', 'in', fields)], context=context)
171
field_name = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=', 'stock.move'), ('name', '=', 'line_number')], context=context)
172
field_parent = self.pool.get('ir.model.fields').search(cr, uid, [('model', '=', 'stock.move'), ('name', '=', 'picking_id')], context=context)
178
parent_id = field_parent[0]
180
name_id = field_name[0]
182
rule_id = self.create(cr, uid, {'name': name,
183
'object_id': object_ids[0],
184
'domain_filter': "[('picking_id', '!=', False), ('picking_id.type', '=', 'in')]",
188
'field_ids': [(6, 0, fields_ids)],
189
'parent_field_id': parent_id,
190
'name_get_field_id': name_id,
193
# Subscribe to the rule
194
self.subscribe(cr, uid, rule_id)