|
| 1 | +<?xml version='1.0' encoding='UTF-8'?> |
| 2 | +<odoo> |
| 3 | + <record id="bom_server_action" model="ir.actions.server"> |
| 4 | + <field name="code"><![CDATA[ |
| 5 | +if record.x_quantity_by_deposit_product == 1 and record.x_unit_sale_product.id: |
| 6 | + raise UserError("Unit sale product should be undefined if this product can not be sold in a smaller unit.") |
| 7 | +if record.x_unit_sale_product: |
| 8 | + existing_bom = env['mrp.bom'].search([('product_tmpl_id', '=',record.x_unit_sale_product.product_tmpl_id.id)], limit=1) |
| 9 | + reordering_rule = env['stock.warehouse.orderpoint'].search_count([('product_id', '=', record.x_unit_sale_product.id)], limit=1) |
| 10 | + bom_vals = { |
| 11 | + 'product_qty': record.x_quantity_by_deposit_product, |
| 12 | + 'type': 'normal', |
| 13 | + 'x_parent_product': record.id, |
| 14 | + 'x_auto_production': True, |
| 15 | + 'bom_line_ids': [(5, 0), (0, 0, { |
| 16 | + 'product_id': record.product_variant_id.id, |
| 17 | + 'product_qty': 1, |
| 18 | + })], |
| 19 | + } |
| 20 | + if record.x_deposit_product: |
| 21 | + bom_vals['byproduct_ids'] = [(5, 0), (0, 0, { |
| 22 | + 'product_id': record.x_deposit_product.product_variant_id.id, |
| 23 | + 'product_qty': 1.0, |
| 24 | + })] |
| 25 | + if existing_bom: |
| 26 | + existing_bom.write(bom_vals) |
| 27 | + else: |
| 28 | + bom_vals['product_tmpl_id'] = record.x_unit_sale_product.product_tmpl_id.id |
| 29 | + env['mrp.bom'].create(bom_vals) |
| 30 | + if not reordering_rule: |
| 31 | + env['stock.warehouse.orderpoint'].create({ |
| 32 | + 'product_id': record.x_unit_sale_product.id, |
| 33 | + 'x_parent_product': record.id, |
| 34 | + 'product_min_qty': 0, |
| 35 | + 'product_max_qty': 0, |
| 36 | + 'qty_multiple': record.x_quantity_by_deposit_product or 1, |
| 37 | + 'route_id': env.ref('mrp.route_warehouse0_manufacture').id, |
| 38 | + 'location_id': env.ref('stock.stock_location_stock').id, |
| 39 | + }) |
| 40 | +else: |
| 41 | + existing_bom = env['mrp.bom'].search([('x_parent_product', '=',record.id)], limit=1) |
| 42 | + reordering_rule = env['stock.warehouse.orderpoint'].search([('x_parent_product', '=', record.id)], limit=1) |
| 43 | + if existing_bom: |
| 44 | + existing_bom.unlink() |
| 45 | + if reordering_rule: |
| 46 | + reordering_rule.unlink() |
| 47 | +]]></field> |
| 48 | + <field name="model_id" ref="product.model_product_template"/> |
| 49 | + <field name="state">code</field> |
| 50 | + <field name="name">Execute Code</field> |
| 51 | + </record> |
| 52 | + <record id="update_sales_taxes_server_action" model="ir.actions.server"> |
| 53 | + <field name="code"><![CDATA[ |
| 54 | +product_taxe = record.taxes_id.filtered(lambda t: t.tax_group_id.name != 'Deposit') |
| 55 | +supplier_taxe = record.supplier_taxes_id.filtered(lambda t: t.tax_group_id.name != 'Deposit') |
| 56 | +if record.x_deposit_product_1: |
| 57 | + product_taxe += record.x_deposit_product_1.taxes_id |
| 58 | + supplier_taxe += record.x_deposit_product_1.supplier_taxes_id |
| 59 | +record['taxes_id'] = [(6, 0, (product_taxe).ids)] |
| 60 | +record['supplier_taxes_id'] = [(6, 0, (supplier_taxe).ids)] |
| 61 | +]]></field> |
| 62 | + <field name="model_id" ref="product.model_product_template"/> |
| 63 | + <field name="state">code</field> |
| 64 | + <field name="name">Execute Code</field> |
| 65 | + </record> |
| 66 | + <record id="update_state" model="ir.actions.server"> |
| 67 | + <field name="child_ids" eval="[(6, 0, [ref('mrp.action_production_order_mark_done')])]"/> |
| 68 | + <field name="model_id" ref="mrp.model_mrp_production"/> |
| 69 | + <field name="state">multi</field> |
| 70 | + <field name="name">Execute Existing Actions</field> |
| 71 | + </record> |
| 72 | + <record id="action_make_deposit_storable_delivery_invoice" model="ir.actions.server"> |
| 73 | + <field name="code"><![CDATA[ |
| 74 | +if record.x_is_a_deposit: |
| 75 | + record.write({'invoice_policy':'delivery', 'type': 'consu', 'is_storable': True}) |
| 76 | +]]></field> |
| 77 | + <field name="model_id" ref="product.model_product_template"/> |
| 78 | + <field name="state">code</field> |
| 79 | + <field name="name">Execute Code</field> |
| 80 | + </record> |
| 81 | +</odoo> |
0 commit comments