|
1 | 1 | <?xml version='1.0' encoding='UTF-8'?> |
2 | 2 | <odoo> |
3 | | - <record id="industry_harvest_and_transfer_server_action" model="ir.actions.server"> |
4 | | - <field name="code"><![CDATA[dest_location = env['stock.location'].search([('complete_name', '=', 'WH/Stock')], limit=1) |
5 | | -if not dest_location: |
6 | | - raise UserError("Destination location not found (WH/Stock).") |
7 | | - |
8 | | -# Confirm harvest |
9 | | -record.action_confirm() |
10 | | -
|
11 | | -# Match inputs and set as done |
12 | | -record['qty_producing'] = record.product_qty |
13 | | -record.action_generate_serial() |
14 | | -record.button_mark_done() |
15 | | -
|
16 | | -# Create a picking |
17 | | -picking = env['stock.picking'].create({ |
18 | | - 'picking_type_id': env.ref('stock.picking_type_internal').id, |
19 | | - 'location_id': record.location_dest_id.id, |
20 | | - 'location_dest_id': dest_location.id, |
21 | | - 'origin': record.name, |
22 | | - 'move_type': 'direct', |
23 | | -}) |
24 | | -
|
25 | | -# Add stock moves for the finished products |
26 | | -for move in record.move_finished_ids.filtered(lambda m: m.product_id.type == 'product'): |
27 | | - env['stock.move'].create({ |
28 | | - 'name': move.product_id.display_name, |
29 | | - 'product_id': move.product_id.id, |
30 | | - 'product_uom_qty': move.quantity_done, |
31 | | - 'product_uom': move.product_uom.id, |
32 | | - 'location_id': record.location_dest_id.id, |
33 | | - 'location_dest_id': dest_location.id, |
34 | | - 'picking_id': picking.id, |
35 | | - }) |
36 | | -
|
37 | | -# Confirm, assign and validate the picking |
38 | | -picking.action_confirm() |
39 | | -picking.action_assign() |
40 | | -picking.button_validate() |
41 | | -
|
42 | | -
|
43 | | -]]></field> |
44 | | - <field name="model_id" ref="mrp.model_mrp_production"/> |
45 | | - <field name="state">code</field> |
46 | | - <field name="name">Harvest and transfer</field> |
47 | | - <field name="usage">base_automation</field> |
48 | | - </record> |
49 | 3 | <record id="industry_check_harvest_is_from_harvest_location_server_action" model="ir.actions.server"> |
50 | | - <field name="code"><![CDATA[if record.picking_type_id.x_is_harvest and not record.location_id.x_harvest_location: |
51 | | - raise UserError ("Source location shall be eligible for harvest.")]]></field> |
52 | | - <field name="model_id" ref="stock.model_stock_picking"/> |
53 | | - <field name="state">code</field> |
54 | 4 | <field name="name">Check Harvest Is From Harvest Location</field> |
| 5 | + <field name="model_id" ref="stock.model_stock_picking"/> |
55 | 6 | <field name="usage">base_automation</field> |
56 | | - </record> |
57 | | - <record id="industry_create_lot_on_validation_server_action" model="ir.actions.server"> |
58 | | - <field name="code"><![CDATA[ |
| 7 | + <field name="state">code</field> |
| 8 | + <field name="code"><![CDATA[if record.picking_type_id.x_is_harvest and not record.location_id.x_is_harvest: |
| 9 | + raise UserError ("Source location shall be eligible for harvest.") |
59 | 10 | for picking in records: |
60 | | - for ml in picking.move_line_ids: |
61 | | - product = ml.product_id |
62 | | -
|
63 | | - if not product or product.tracking != 'lot': |
64 | | - continue |
65 | | -
|
66 | | - if not ml.lot_id: |
67 | | - serial = env['ir.sequence'].next_by_code('auto.lot.serial') |
68 | | - lot = env['stock.lot'].create({ |
69 | | - 'name': serial, |
70 | | - 'product_id': product.id, |
71 | | - 'company_id': picking.company_id.id, |
72 | | - }) |
73 | | - ml.write({'lot_id': lot.id}) |
| 11 | + for ml in picking.move_line_ids.filtered(lambda line: line.product_id and line.product_id.tracking == 'lot' and not line.lot_id): |
| 12 | + serial = env['ir.sequence'].next_by_code('auto.lot.serial') |
| 13 | + lot = env['stock.lot'].create({ |
| 14 | + 'name': serial, |
| 15 | + 'product_id': ml.product_id.id, |
| 16 | + 'company_id': picking.company_id.id, |
| 17 | + }) |
| 18 | + ml.write({'lot_id': lot.id}) |
74 | 19 | ]]></field> |
75 | | - <!-- <field name="code"><![CDATA[ |
76 | | -generated_serial = env['ir.sequence'].next_by_code('auto.lot.serial') |
77 | | -prefix = generated_serial.split('-')[0] + '-' |
78 | | -existing_lots = set( |
79 | | - env['stock.lot'].search([ |
80 | | - ('name', 'like', prefix + '%') |
81 | | - ]).mapped('name') |
82 | | -) |
83 | | -
|
84 | | -for picking in records: |
85 | | - for ml in picking.move_line_ids: |
86 | | - product = ml.product_id |
87 | | - if not product or product.tracking != 'lot': |
88 | | - continue |
89 | | -
|
90 | | - if not ml.lot_id: |
91 | | - serial = generated_serial |
92 | | - while serial in existing_lots: |
93 | | - serial = env['ir.sequence'].next_by_code('auto.lot.serial') |
94 | | -
|
95 | | - lot = env['stock.lot'].create({ |
96 | | - 'name': serial, |
97 | | - 'product_id': product.id, |
98 | | - 'company_id': picking.company_id.id, |
99 | | - }) |
100 | | - ml.write({'lot_id': lot.id}) |
101 | | - ]]></field> --> |
102 | | - <field name="model_id" ref="stock.model_stock_picking"/> |
103 | | - <field name="state">code</field> |
104 | | - <field name="name">Action for Assign Serial</field> |
105 | | - <field name="usage">base_automation</field> |
106 | 20 | </record> |
107 | 21 | </odoo> |
0 commit comments