Skip to content

Commit

Permalink
[ENH]stages utomatic transition propsoal based on automated actions
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronHForgeFlow committed Sep 25, 2019
1 parent 5d7c293 commit abfa6f9
Show file tree
Hide file tree
Showing 3 changed files with 302 additions and 0 deletions.
1 change: 1 addition & 0 deletions ao_rma/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"base_automation",
],
"data": ["data/rma_stage.xml",
"data/base_automation_data.xml",
"views/rma_operation_view.xml",
"views/rma_order_line_view.xml",
"wizards/rma_order_line_make_repair_view.xml",
Expand Down
261 changes: 261 additions & 0 deletions ao_rma/data/base_automation_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
<?xml version="1.0" encoding="utf-8"?>
<!--TODO: no update to 1-->
<odoo noupdate="0">

<!--FROM NEW TO ANOTHER-->

<record id="new_awaiting_return" model="base.automation">
<field name="name">New > Awaiting Return</field>
<field name="model_id" ref="rma.model_rma_order_line"/>
<field name="state">object_write</field>
<field name="trigger">on_write</field>
<field name="action">object_write</field>
<field name="active" eval="True"/>
<field name="filter_pre_domain">['|', ('state', '=', 'draft'), ('state', '=', 'to_approve')]</field>
<field name="filter_domain">[('state', '=', 'approved'), ('operation_id.repair_type_id.under_warranty', '=', True)]</field>
</record>

<record id="new_awaiting_return_action" model="ir.server.object.lines">
<field name="server_id" ref="ao_rma.new_awaiting_return_ir_actions_server"/>
<field name="type">reference</field>
<field name="value">5</field>
<field name="col1" search="[('name','=','stage_id'), ('model_id', '=', ref('rma.model_rma_order_line'))]" model="ir.model.fields"/>
<field name="resource_ref" eval="'base.kanban.stage,%s' %ref('ao_rma.awaiting_return') "/>
</record>

<!---->
<record id="new_awaiting_payment" model="base.automation">
<field name="name">New > Awaiting Payment</field>
<field name="model_id" ref="rma.model_rma_order_line"/>
<field name="state">object_write</field>
<field name="trigger">on_write</field>
<field name="action">object_write</field>
<field name="active" eval="True"/>
<field name="filter_pre_domain">['|', ('state', '=', 'draft'), ('state', '=', 'to_approve')]</field>
<field name="filter_domain">[('state', '=', 'approved'), ('operation_id.repair_type_id.under_warranty', '=', False), ('sale_policy', '=', 'ordered')]</field>
</record>

<record id="new_awaiting_payment_action" model="ir.server.object.lines">
<field name="server_id" ref="ao_rma.new_awaiting_payment_ir_actions_server"/>
<field name="type">reference</field>
<field name="value">5</field>
<field name="col1" search="[('name','=','stage_id'), ('model_id', '=', ref('rma.model_rma_order_line'))]" model="ir.model.fields"/>
<field name="resource_ref" eval="'base.kanban.stage,%s' %ref('ao_rma.awaiting_payment') "/>
</record>

<!--FROM AWAITING RETURN TO ANOTHER-->

<record id="awaiting_return_new" model="base.automation">
<field name="name">Awaiting Return > New</field>
<field name="model_id" ref="rma.model_rma_order_line"/>
<field name="state">object_write</field>
<field name="trigger">on_write</field>
<field name="action">object_write</field>
<field name="active" eval="True"/>
<field name="filter_pre_domain">[('state', '=', 'approved')]</field>
<field name="filter_domain">[('state', '=', 'draft')]</field>
</record>

<record id="awaiting_return_new_action" model="ir.server.object.lines">
<field name="server_id" ref="ao_rma.awaiting_return_new_ir_actions_server"/>
<field name="type">reference</field>
<field name="value">5</field>
<field name="col1" search="[('name','=','stage_id'), ('model_id', '=', ref('rma.model_rma_order_line'))]" model="ir.model.fields"/>
<field name="resource_ref" eval="'base.kanban.stage,%s' %ref('ao_rma.rma_new') "/>
</record>

<!---->
<record id="awaiting_return_awaiting_eval" model="base.automation">
<field name="name">Awaiting return > Awaiting Eval/Repair</field>
<field name="model_id" ref="rma.model_rma_order_line"/>
<field name="state">object_write</field>
<field name="trigger">on_write</field>
<field name="action">object_write</field>
<field name="active" eval="True"/>
<field name="filter_pre_domain">[('qty_to_repair', '>', 0)]</field>
<field name="filter_domain">[('qty_to_repair', '=', '0'), ('qty_to_receive', '=', 0), ('qty_repaired', '=', '0')]</field>
</record>

<record id="awaiting_return_awaiting_eval_action" model="ir.server.object.lines">
<field name="server_id" ref="ao_rma.awaiting_return_awaiting_eval_ir_actions_server"/>
<field name="type">reference</field>
<field name="value">5</field>
<field name="col1" search="[('name','=','stage_id'), ('model_id', '=', ref('rma.model_rma_order_line'))]" model="ir.model.fields"/>
<field name="resource_ref" eval="'base.kanban.stage,%s' %ref('ao_rma.awaiting_eval') "/>
</record>

<!--FROM AWAITING EVAL/REPAIR TO ANOTHER-->
<record id="awaiting_eval_under_repair" model="base.automation">
<field name="name">Awaiting Eval/Repair > Under Repair/Being evaluated</field>
<field name="model_id" ref="rma.model_rma_order_line"/>
<field name="state">object_write</field>
<field name="trigger">on_write</field>
<field name="action">object_write</field>
<field name="active" eval="True"/>
<field name="filter_pre_domain">[('state', '=', 'approved'), ('operation_id.repair_type_id.under_warranty', '=', True), ('qty_under_repair', '=', 0)]</field>
<field name="filter_domain">[('state', '=', 'approved'), ('operation_id.repair_type_id.under_warranty', '=', True), ('qty_under_repair', '>', 0)]</field>
</record>

<record id="awaiting_eval_under_repair_action" model="ir.server.object.lines">
<field name="server_id" ref="ao_rma.awaiting_eval_under_repair_ir_actions_server"/>
<field name="type">reference</field>
<field name="value">5</field>
<field name="col1" search="[('name','=','stage_id'), ('model_id', '=', ref('rma.model_rma_order_line'))]" model="ir.model.fields"/>
<field name="resource_ref" eval="'base.kanban.stage,%s' %ref('ao_rma.under_repair') "/>
</record>
<!---->
<record id="awaiting_eval_awaiting_payment" model="base.automation">
<field name="name">Awaiting Eval/Repair > Awaiting Payment</field>
<field name="model_id" ref="rma.model_rma_order_line"/>
<field name="state">object_write</field>
<field name="trigger">on_write</field>
<field name="action">object_write</field>
<field name="active" eval="True"/>
<field name="filter_pre_domain">[('state', '=', 'approved'), ('operation_id.repair_type_id.under_warranty', '=', False), ('qty_under_repair', '=', 0)]</field>
<field name="filter_domain">[('state', '=', 'approved'), ('operation_id.repair_type_id.under_warranty', '=', False), ('qty_under_repair', '>', 0)]</field>
</record>

<record id="awaiting_eval_awaiting_payment_action" model="ir.server.object.lines">
<field name="server_id" ref="ao_rma.awaiting_eval_awaiting_payment_ir_actions_server"/>
<field name="type">reference</field>
<field name="value">5</field>
<field name="col1" search="[('name','=','stage_id'), ('model_id', '=', ref('rma.model_rma_order_line'))]" model="ir.model.fields"/>
<field name="resource_ref" eval="'base.kanban.stage,%s' %ref('ao_rma.awaiting_payment') "/>
</record>

<!--FROM Under Repair/Being Evaluated TO ANOTHER-->
<record id="under_repair_ready_to_ship" model="base.automation">
<field name="name">Under Repair/Being Evaluated > Ready To Be Shipped</field>
<field name="model_id" ref="rma.model_rma_order_line"/>
<field name="state">object_write</field>
<field name="trigger">on_write</field>
<field name="action">object_write</field>
<field name="active" eval="True"/>
<field name="filter_pre_domain">[('state', '=', 'approved'), ('operation_id.repair_type_id.to_refurbish', '=', False), ('qty_under_repair', '>', 0)]</field>
<field name="filter_domain">[('state', '=', 'approved'), ('qty_under_repair', '=', 0), ('qty_to_repair', '=', 0), ('qty_repaired', '>', 0)]</field>
</record>

<record id="under_repair_ready_to_ship_action" model="ir.server.object.lines">
<field name="server_id" ref="ao_rma.under_repair_ready_to_ship_ir_actions_server"/>
<field name="type">reference</field>
<field name="value">5</field>
<field name="col1" search="[('name','=','stage_id'), ('model_id', '=', ref('rma.model_rma_order_line'))]" model="ir.model.fields"/>
<field name="resource_ref" eval="'base.kanban.stage,%s' %ref('ao_rma.rma_to_ship') "/>
</record>
<!---->
<record id="under_repair_ready_to_refurbed" model="base.automation">
<field name="name">Under Repair/Being Evaluated > To Be Refurbed</field>
<field name="model_id" ref="rma.model_rma_order_line"/>
<field name="state">object_write</field>
<field name="trigger">on_write</field>
<field name="action">object_write</field>
<field name="active" eval="True"/>
<field name="filter_pre_domain">[('state', '=', 'approved'), ('operation_id.repair_type_id.to_refurbish', '=', True), ('qty_under_repair', '>', 0)]</field>
<field name="filter_domain">[('state', '=', 'approved'), ('qty_repaired', '>', 0), ('qty_under_repair', '=', 0)]</field>
</record>

<record id="under_repair_ready_to_refurbed_action" model="ir.server.object.lines">
<field name="server_id" ref="ao_rma.under_repair_ready_to_refurbed_ir_actions_server"/>
<field name="type">reference</field>
<field name="value">5</field>
<field name="col1" search="[('name','=','stage_id'), ('model_id', '=', ref('rma.model_rma_order_line'))]" model="ir.model.fields"/>
<field name="resource_ref" eval="'base.kanban.stage,%s' %ref('ao_rma.to_refurbed') "/>
</record>

<!--FROM Awaiting Payment TO ANOTHER-->
<record id="awaiting_payment_to_awaiting_return" model="base.automation">
<field name="name">Awaiting Payment > Awaiting Return</field>
<field name="model_id" ref="rma.model_rma_order_line"/>
<field name="state">object_write</field>
<field name="trigger">on_write</field>
<field name="action">object_write</field>
<field name="active" eval="True"/>
<field name="filter_pre_domain">[('state', '=', 'approved'), ('operation_id.repair_type_id.under_warranty', '=', False), ('sale_invoice_status', '=', 'unpaid')]</field>
<field name="filter_domain">[('state', '=', 'approved'), ('operation_id.repair_type_id.under_warranty', '=', False), ('sale_invoice_status', '=', 'paid')]</field>
</record>

<record id="awaiting_payment_to_awaiting_return_action" model="ir.server.object.lines">
<field name="server_id" ref="ao_rma.awaiting_payment_to_awaiting_return_ir_actions_server"/>
<field name="type">reference</field>
<field name="value">5</field>
<field name="col1" search="[('name','=','stage_id'), ('model_id', '=', ref('rma.model_rma_order_line'))]" model="ir.model.fields"/>
<field name="resource_ref" eval="'base.kanban.stage,%s' %ref('ao_rma.awaiting_return') "/>
</record>
<!---->
<record id="awaiting_payment_to_under_repair" model="base.automation">
<field name="name">Awaiting Payment > Under Repair/Being Evaluated</field>
<field name="model_id" ref="rma.model_rma_order_line"/>
<field name="state">object_write</field>
<field name="trigger">on_write</field>
<field name="action">object_write</field>
<field name="active" eval="True"/>
<field name="filter_pre_domain">[('state', '=', 'approved'), ('operation_id.repair_type_id.under_warranty', '=', False), ('repair_invoice_status', '=', 'unpaid')]</field>
<field name="filter_domain">[('state', '=', 'approved'), ('operation_id.repair_type_id.under_warranty', '=', False), ('repair_invoice_status', '>', 'paid')]</field>
</record>

<record id="awaiting_payment_to_under_repair_action" model="ir.server.object.lines">
<field name="server_id" ref="ao_rma.awaiting_payment_to_under_repair_ir_actions_server"/>
<field name="type">reference</field>
<field name="value">5</field>
<field name="col1" search="[('name','=','stage_id'), ('model_id', '=', ref('rma.model_rma_order_line'))]" model="ir.model.fields"/>
<field name="resource_ref" eval="'base.kanban.stage,%s' %ref('ao_rma.under_repair') "/>
</record>
<!--FROM To Be Refurbed TO ANOTHER-->

<record id="to_refurb_to_close" model="base.automation">
<field name="name">To be Refurbed > Closed</field>
<field name="model_id" ref="rma.model_rma_order_line"/>
<field name="state">object_write</field>
<field name="trigger">on_write</field>
<field name="action">object_write</field>
<field name="active" eval="True"/>
<field name="filter_pre_domain">[('state', '=', 'approved'), ('operation_id.repair_type_id.to_refurbish', '=', True), ('qty_to_deliver', '>', 0)]</field>
<field name="filter_domain">[('state', '=', 'approved'), ('operation_id.repair_type_id.to_refurbish', '=', True), ('qty_to_deliver', '=', 0)]</field>
</record>

<record id="to_refurb_to_close_action" model="ir.server.object.lines">
<field name="server_id" ref="ao_rma.to_refurb_to_close_ir_actions_server"/>
<field name="type">reference</field>
<field name="value">5</field>
<field name="col1" search="[('name','=','stage_id'), ('model_id', '=', ref('rma.model_rma_order_line'))]" model="ir.model.fields"/>
<field name="resource_ref" eval="'base.kanban.stage,%s' %ref('ao_rma.rma_closed') "/>
</record>
<!--FROM Ready to be shipped TO ANOTHER-->
<record id="ready_ship_to_csr_follow" model="base.automation">
<field name="name">Ready to be Shipped > CSR Followup</field>
<field name="model_id" ref="rma.model_rma_order_line"/>
<field name="state">object_write</field>
<field name="trigger">on_write</field>
<field name="action">object_write</field>
<field name="active" eval="True"/>
<field name="filter_pre_domain">[('state', '=', 'approved'), ('operation_id.repair_type_id.under_warranty', '=', False), ('qty_to_deliver', '>', 0)]</field>
<field name="filter_domain">[('state', '=', 'approved'), ('operation_id.repair_type_id.under_warranty', '=', False), ('qty_to_deliver', '=', 0)]</field>
</record>

<record id="ready_ship_to_csr_follow_action" model="ir.server.object.lines">
<field name="server_id" ref="ao_rma.ready_ship_to_csr_follow_ir_actions_server"/>
<field name="type">reference</field>
<field name="value">5</field>
<field name="col1" search="[('name','=','stage_id'), ('model_id', '=', ref('rma.model_rma_order_line'))]" model="ir.model.fields"/>
<field name="resource_ref" eval="'base.kanban.stage,%s' %ref('ao_rma.csr_needed') "/>
</record>
<!---->
<record id="ready_ship_to_closed" model="base.automation">
<field name="name">Ready to be Shipped > Closed</field>
<field name="model_id" ref="rma.model_rma_order_line"/>
<field name="state">object_write</field>
<field name="trigger">on_write</field>
<field name="action">object_write</field>
<field name="active" eval="True"/>
<field name="filter_pre_domain">[('state', '=', 'approved'), ('operation_id.repair_type_id.under_warranty', '=', True), ('qty_to_deliver', '>', 0)]</field>
<field name="filter_domain">[('state', '=', 'approved'), ('operation_id.repair_type_id.under_warranty', '=', True), ('qty_to_deliver', '=', 0)]</field>
</record>

<record id="ready_ship_to_closed_action" model="ir.server.object.lines">
<field name="server_id" ref="ao_rma.ready_ship_to_closed_ir_actions_server"/>
<field name="type">reference</field>
<field name="value">5</field>
<field name="col1" search="[('name','=','stage_id'), ('model_id', '=', ref('rma.model_rma_order_line'))]" model="ir.model.fields"/>
<field name="resource_ref" eval="'base.kanban.stage,%s' %ref('ao_rma.csr_needed') "/>
</record>
</odoo>
40 changes: 40 additions & 0 deletions ao_rma/models/rma_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,46 @@ class RmaOrderLine(models.Model):
readonly=False, states={'done': [('readonly', True)]},
)

sale_invoice_status = fields.Selection(
compute='compute_sale_invoice_status',
string="Customer Sale Invoice Status",
selection = [
('unpaid', 'Pending to be paid'),
('paid', 'Fully Paid')]
)

repair_invoice_status = fields.Selection(
compute='compute_repair_invoice_status',
string="Customer Repair Invoice Status",
selection = [
('unpaid', 'Pending to be paid'),
('paid', 'Fully Paid')]
)

@api.multi
def compute_sale_invoice_status(self):
for line in self:
if not line.sale_line_ids:
line.sale_invoice_status == 'paid'
continue
statuses = line.sale_line_ids.mapped('invoice_status')
if len(statuses == 1) and 'paid' in statuses:
line.sale_invoice_status == 'paid'
else:
line.sale_invoice_status == 'unpaid'

@api.multi
def compute_repair_invoice_status(self):
for line in self:
if not line.repair_ids:
line.repair_ids == 'paid'
continue
statuses = line.repair_ids.mapped('invoice_id.state')
if len(statuses == 1) and 'paid' in statuses:
line.repair_invoice_status == 'paid'
else:
line.repair_invoice_status == 'unpaid'

@api.constrains('in_route_id', 'out_route_id', 'location_id',
'in_warehouse_id', 'out_warehouse_id', 'operation_id')
def check_operation_consistency(self):
Expand Down

0 comments on commit abfa6f9

Please sign in to comment.