Skip to content

Commit

Permalink
migrate stock picking and settlements views
Browse files Browse the repository at this point in the history
  • Loading branch information
gborelli committed Nov 10, 2014
1 parent 7c7d95c commit ef65ace
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 86 deletions.
2 changes: 1 addition & 1 deletion sale_commission/model/settled.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class settlement(models.Model):
default=fields.Datetime.now()
)

# TODO: I think a workflow is necessary to manage 'cancel' state/transition
# TODO: Workflow is necessary to manage 'cancel' state/transition
state = fields.Selection(
[
("invoiced", "Invoiced"),
Expand Down
35 changes: 17 additions & 18 deletions sale_commission/model/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,20 @@ class stock_picking(models.Model):
string="Agents"
)

# TODO: migrate stock.picking._invoice_line_hook
# def _invoice_line_hook(self, cr, uid, move_line, invoice_line_id, context=None):
# '''Call after the creation of the invoice line'''
# if context is None:
# context = {}
# agent_pool = self.pool.get('invoice.line.agent')
# super(stock_picking, self)._invoice_line_hook(cr, uid, move_line, invoice_line_id, context=context)
# if move_line and move_line.sale_line_id and not move_line.sale_line_id.product_id.commission_exent:
# so_ref = move_line.sale_line_id.order_id
# for so_agent_id in so_ref.sale_agent_ids:
# vals = {
# 'invoice_line_id': invoice_line_id,
# 'agent_id': so_agent_id.agent_id.id,
# 'commission_id': so_agent_id.commission_id.id,
# 'settled': False
# }
# line_agent_id = agent_pool.create(cr, uid, vals, context=context)
# agent_pool.calculate_commission(cr, uid, [line_agent_id], context=context)
def _invoice_line_hook(self, cr, uid, move_line, invoice_line_id, context=None):
'''Call after the creation of the invoice line'''
if context is None:
context = {}
agent_pool = self.pool.get('invoice.line.agent')
super(stock_picking, self)._invoice_line_hook(cr, uid, move_line, invoice_line_id, context=context)
if move_line and move_line.sale_line_id and not move_line.sale_line_id.product_id.commission_exent:
so_ref = move_line.sale_line_id.order_id
for so_agent_id in so_ref.sale_agent_ids:
vals = {
'invoice_line_id': invoice_line_id,
'agent_id': so_agent_id.agent_id.id,
'commission_id': so_agent_id.commission_id.id,
'settled': False
}
line_agent_id = agent_pool.create(cr, uid, vals, context=context)
agent_pool.calculate_commission(cr, uid, [line_agent_id], context=context)
134 changes: 81 additions & 53 deletions sale_commission/view/settled_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,26 @@
<field name="model">settlement.agent</field>
<field name="arch" type="xml">
<form string="Settlement agent">
<field name="agent_id"/>
<field name="total_per"/>
<field name="total_sections"/>
<field name="total"/>
<notebook colspan="4">
<page string="Invoices">
<field name="invoices" colspan="4" nolabel="1"/>
</page>
<page string="Line details">
<field name="lines" colspan="4" nolabel="1"/>
</page>
</notebook>
<group>
<field name="agent_id"/>
<field name="total_per"/>
<field name="total_sections"/>
<field name="total"/>
</group>
<group colspan="4">
<notebook colspan="4">
<page string="Invoices">
<field name="invoices"
colspan="4"
nolabel="1" />
</page>
<page string="Line details">
<field name="lines"
colspan="4"
nolabel="1" />
</page>
</notebook>
</group>
</form>
</field>
</record>
Expand Down Expand Up @@ -68,8 +76,12 @@
</group>
<newline/>
<group expand="0" string="Group By...">
<filter string="Settlement" context="{'group_by': 'settlement_id'}" icon="terp-dolar"/>
<filter string="Agent" context="{'group_by': 'agent_id'}" icon="terp-personal"/>
<filter string="Settlement"
context="{'group_by': 'settlement_id'}"
icon="terp-dolar" />
<filter string="Agent"
context="{'group_by': 'agent_id'}"
icon="terp-personal" />
</group>
</search>
</field>
Expand Down Expand Up @@ -107,8 +119,12 @@
</group>
<newline/>
<group expand="0" string="Group By...">
<filter string="Agent" context="{'group_by': 'agent_id'}" icon="terp-personal"/>
<filter string="Invoice" context="{'group_by': 'invoice_id'}" icon="terp-dolar"/>
<filter string="Agent"
context="{'group_by': 'agent_id'}"
icon="terp-personal" />
<filter string="Invoice"
context="{'group_by': 'invoice_id'}"
icon="terp-dolar" />
</group>
</search>
</field>
Expand All @@ -119,14 +135,15 @@
<field name="model">settled.invoice.agent</field>
<field name="arch" type="xml">
<form string="Settled invoices summary">
<field name="agent_id"/>
<field name="invoice_id"/>
<field name="invoice_number"/>
<field name="invoice_date"/>
<field name="invoice_amount"/>
<field name="settled_amount"/>
<!--field name="currency_id"/-->
<newline/>
<group>
<field name="agent_id"/>
<field name="invoice_id"/>
<field name="invoice_number"/>
<field name="invoice_date"/>
<field name="invoice_amount"/>
<field name="settled_amount"/>
<!--field name="currency_id"/-->
</group>
</form>
</field>
</record>
Expand All @@ -136,14 +153,18 @@
<field name="model">settlement</field>
<field name="arch" type="xml">
<search string="Settlement">
<group>
<filter icon="terp-check" string="Settled" domain="[('state', '=', ('settled'))]"/>
<filter icon="terp-dolar" string="Invoices" domain="[('state', '=', ('invoiced'))]"/>
<filter icon="terp-gtk-stop" string="Cancel" domain="[('state', '=', ('cancel'))]"/>
</group>
<field name="name"/>
<field name="date_from"/>
<field name="date_to"/>

<group expand="0" string="Filter by...">
<filter icon="terp-check" string="Settled"
domain="[('state', '=', ('settled'))]" />
<filter icon="terp-dolar" string="Invoices"
domain="[('state', '=', ('invoiced'))]" />
<filter icon="terp-gtk-stop" string="Cancel"
domain="[('state', '=', ('cancel'))]" />
</group>
</search>
</field>
</record>
Expand Down Expand Up @@ -190,27 +211,7 @@
<field name="model">settlement</field>
<field name="arch" type="xml">
<form string="Settlements">
<group>
<field name="name"/>
<field name="total"/>
<field name="date_from"/>
<field name="date_to"/>
</group>
<group colspan="4">
<label string="Agents summary"/>
<field name="settlement_agent_id" nolabel="1">
<tree string="Agents summary" editable="top">
<field name="agent_id"/>
<field name="total_per"/>
<field name="total_sections"/>
<field name="total" sum="Settled total"/>
</tree>
</field>
</group>
<group>
<field name="state"/>
</group>
<group colspan="4">
<header>
<button name="%(action_settled_invoice)d"
string="Create Invoices"
attrs="{'invisible': [('state','!=','settled')]}"
Expand All @@ -221,20 +222,47 @@
name="action_cancel"
type="object"
states="settled" />
</group>

<field name="state"
widget="statusbar"
statusbar_visible="settled,invoiced,cancel" statusbar_colors='{"invoiced":"blue","cancel":"red"}' />
</header>

<sheet>
<group>
<group>
<field name="name"/>
<field name="total"/>
</group>
<group>
<field name="date_from"/>
<field name="date_to"/>
</group>
</group>
<separator string="Agents summary" />
<group colspan="4">
<field name="settlement_agent_id" nolabel="1">
<tree string="Agents summary" editable="top">
<field name="agent_id"/>
<field name="total_per"/>
<field name="total_sections"/>
<field name="total" sum="Settled total"/>
</tree>
</field>
</group>
</sheet>
</form>
</field>
</record>


<record model="ir.actions.act_window" id="act_settlement">
<field name="name">Settlement Summary</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">settlement</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_settlement_tree"/>

<field name="search_view_id" ref="view_settlement_search"/>
</record>

<menuitem name="Settlements"
Expand Down
26 changes: 12 additions & 14 deletions sale_commission/view/stock_picking_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@
<openerp>
<data>

<!-- TODO: migrate stock.picking views, they don't exist in Odoo v8 -->
<!-- <record id="stock_picking_form_add_agent_field" model="ir.ui.view">
<record id="stock_picking_form_add_agent_field" model="ir.ui.view">
<field name="name">stock.picking.form.add_agent_field</field>
<field name="model">stock.picking</field>
<field name="type">form</field>
<field name="inherit_id" ref="stock.view_picking_out_form"/>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<field name="move_type" position="after" >
<group colspan="2" col="2">
<separator colspan="2" string="Agents/Consultancy"/>
<field name="agent_ids" colspan="2" rowspan="4" readonly="1" nolabel="1">
<tree string="Agents" >
<field name="name"/>
</tree>
</field>
</group>
</field>
<notebook position="inside">
<page string="Agents/Consultancy">
<field name="agent_ids" readonly="1" nolabel="1">
<tree string="Agents" >
<field name="name"/>
</tree>
</field>
</page>
</notebook>
</field>
</record> -->
</record>

<!--record id="stock_picking_tree_add_agent_field" model="ir.ui.view">
<field name="name">stock.picking.tree.add_agent_field</field>
Expand Down

0 comments on commit ef65ace

Please sign in to comment.