Last active
August 29, 2015 14:09
-
-
Save eLBati/4acd014aade44bdd08fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/sale_commission/__init__.py b/sale_commission/__init__.py | |
index 98429f7..ad47c64 100644 | |
--- a/sale_commission/__init__.py | |
+++ b/sale_commission/__init__.py | |
@@ -2,7 +2,8 @@ | |
############################################################################## | |
# | |
# OpenERP, Open Source Management Solution | |
-# Copyright (C) 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>). All Rights Reserved | |
+# Copyright (C) 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>). | |
+# All Rights Reserved | |
# $Id$ | |
# | |
# This program is free software: you can redistribute it and/or modify | |
@@ -19,14 +20,10 @@ | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# | |
############################################################################## | |
- | |
-import sale_agent | |
-import invoice | |
-import partner_agent | |
-import partner | |
-import settled | |
-import sale_order | |
-import stock_picking | |
-import wizard | |
- | |
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: | |
+from . import sale_agent | |
+from . import invoice | |
+from . import partner_agent | |
+from . import partner | |
+from . import settled | |
+from . import sale_order | |
+from . import stock_picking | |
diff --git a/sale_commission/__openerp__.py b/sale_commission/__openerp__.py | |
index 225c7b6..1320836 100644 | |
--- a/sale_commission/__openerp__.py | |
+++ b/sale_commission/__openerp__.py | |
@@ -2,7 +2,8 @@ | |
############################################################################## | |
# | |
# OpenERP, Open Source Management Solution | |
-# Copyright (C) 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>). All Rights Reserved | |
+# Copyright (C) 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>). | |
+# All Rights Reserved | |
# $Id$ | |
# | |
# This program is free software: you can redistribute it and/or modify | |
@@ -46,23 +47,33 @@ Contributors | |
Davide Corio <davide.corio@domsense.com> | |
Joao Alfredo Gama Batista <joao.gama@savoirfairelinux.com> | |
Sandy Carter <sandy.carter@savoirfairelinux.com> | |
+Giorgio Borelli <giorgio.borelli@abstract.it> | |
""", | |
- 'data': [ | |
- 'security/ir.model.access.csv', | |
- 'sale_agent_view.xml', | |
- 'partner_agent_view.xml', | |
- 'wizard/wizard_invoice.xml', | |
- 'partner_view.xml', | |
- 'settled_view.xml', | |
- 'invoice_view.xml', | |
- 'sale_order_view.xml', | |
- 'product_view.xml', | |
- 'stock_picking_view.xml', | |
- 'cc_commission_report.xml', | |
+ "depends": [ | |
+ "base", | |
+ "account", | |
+ "hr", | |
+ "sale", | |
+ "stock" | |
], | |
- 'demo': [ | |
+ "data": [ | |
+ "security/ir.model.access.csv", | |
+ "view/sale_agent_view.xml", | |
+ "view/partner_agent_view.xml", | |
+ "wizard/wizard_invoice.xml", | |
+ "wizard/wizard_settle.xml", | |
+ "view/partner_view.xml", | |
+ "view/settled_view.xml", | |
+ "view/invoice_view.xml", | |
+ "view/sale_order_view.xml", | |
+ "view/product_view.xml", | |
+ "view/stock_picking_view.xml", | |
+ # 'cc_commission_report.xml' | |
], | |
- 'active': False, | |
- 'installable': True | |
+ "demo": [ | |
+ 'demo/sale_agent_demo.xml', | |
+ ], | |
+ "active": False, | |
+ "installable": True | |
} | |
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: | |
diff --git a/sale_commission/cc_commission_report.xml b/sale_commission/cc_commission_report.xml | |
deleted file mode 100644 | |
index 925cc6a..0000000 | |
--- a/sale_commission/cc_commission_report.xml | |
+++ /dev/null | |
@@ -1,13 +0,0 @@ | |
-<?xml version="1.0" encoding="utf-8"?> | |
-<openerp> | |
- <data> | |
- | |
- <report auto="True" | |
- id="settlement_report" | |
- model="settlement" | |
- name="settlement.report" | |
- rml="sale_commission/report/settlement_report.rml" | |
- string="Settlement report"/> | |
- | |
- </data> | |
-</openerp> | |
\ No newline at end of file | |
diff --git a/sale_commission/i18n/it.po b/sale_commission/i18n/it.po | |
index b647050..9e983b0 100644 | |
--- a/sale_commission/i18n/it.po | |
+++ b/sale_commission/i18n/it.po | |
@@ -767,7 +767,7 @@ msgstr "Reports" | |
#: field:invoice.line.agent,quantity:0 | |
#: field:settled.invoice.agent,settled_amount:0 | |
msgid "Settled amount" | |
-msgstr "Import liquidato" | |
+msgstr "Importo liquidato" | |
#. module: sale_commission | |
#: field:invoice.line.agent,commission_id:0 | |
diff --git a/sale_commission/invoice.py b/sale_commission/invoice.py | |
index 4cee82f..a80dfba 100644 | |
--- a/sale_commission/invoice.py | |
+++ b/sale_commission/invoice.py | |
@@ -2,7 +2,8 @@ | |
############################################################################## | |
# | |
# OpenERP, Open Source Management Solution | |
-# Copyright (C) 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>). All Rights Reserved | |
+# Copyright (C) 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>). | |
+# All Rights Reserved | |
# $Id$ | |
# | |
# This program is free software: you can redistribute it and/or modify | |
@@ -22,119 +23,174 @@ | |
"""invoice agents""" | |
-from osv import fields, orm | |
-from tools.translate import _ | |
+from openerp import models, fields, api, _ | |
-class invoice_line_agent(orm.Model): | |
+class invoice_line_agent(models.Model): | |
"""invoice agents""" | |
_name = "invoice.line.agent" | |
- _columns = { | |
- 'invoice_line_id': fields.many2one('account.invoice.line', 'Invoice Line', required=True, ondelete='cascade', | |
- help=''), | |
- 'invoice_id': fields.related('invoice_line_id', 'invoice_id', type='many2one', relation='account.invoice', | |
- string='Invoice'), | |
- 'invoice_date': fields.related('invoice_id', type='date_invoice', readonly=True), | |
- 'agent_id': fields.many2one('sale.agent', 'Agent', required=True, ondelete='cascade', help=''), | |
- 'commission_id': fields.many2one('commission', 'Applied commission', required=True, ondelete='cascade', | |
- help=''), | |
- 'settled': fields.boolean('Settled', readonly=True), | |
- 'quantity': fields.float('Settled amount') | |
- } | |
- _defaults = { | |
- 'settled': False, | |
- 'quantity': 0 | |
- } | |
+ | |
+ invoice_line_id = fields.Many2one( | |
+ "account.invoice.line", | |
+ string="Invoice Line", | |
+ required=True, | |
+ ondelete="cascade" | |
+ ) | |
+ | |
+ invoice_id = fields.Many2one( | |
+ "account.invoice", | |
+ string="Invoice", | |
+ related="invoice_line_id.invoice_id" | |
+ ) | |
+ | |
+ invoice_date = fields.Date( | |
+ string="Invoice date", | |
+ related="invoice_id.date_invoice", | |
+ readonly=True | |
+ ) | |
+ | |
+ agent_id = fields.Many2one( | |
+ "sale.agent", | |
+ string="Agent", | |
+ required=True, | |
+ ondelete="cascade" | |
+ ) | |
+ | |
+ commission_id = fields.Many2one( | |
+ "commission", | |
+ string="Applied commission", | |
+ required=True, | |
+ ondelete="cascade", | |
+ ) | |
+ | |
+ settled = fields.Boolean( | |
+ string="Settled", | |
+ readonly=True, | |
+ default=False | |
+ ) | |
+ | |
+ quantity = fields.Float(string="Settled amount", default=0) | |
def calculate_commission(self, cr, uid, ids, context=None): | |
if context is None: | |
context = {} | |
for line_agent in self.browse(cr, uid, ids, context): | |
- if line_agent.commission_id.type == 'fijo' and line_agent.commission_id.fix_qty: | |
- quantity = line_agent.invoice_line_id.price_subtotal * (line_agent.commission_id.fix_qty / 100.0) | |
- self.write(cr, uid, line_agent.id, {'quantity': quantity}, context=context) | |
- | |
- def onchange_agent_id(self, cr, uid, ids, agent_id, context=None): | |
- """al cambiar el agente se le carga la comisión""" | |
- if context is None: | |
- context = {} | |
+ commission_type = line_agent.commission_id.type | |
+ if commission_type == 'fijo' and line_agent.commission_id.fix_qty: | |
+ subtotal = line_agent.invoice_line_id.price_subtotal | |
+ fix_qty = line_agent.commission_id.fix_qty | |
+ vals = {'quantity': subtotal * (fix_qty / 100.0)} | |
+ self.write(cr, uid, line_agent.id, vals, context=context) | |
+ | |
+ @api.onchange("agent_id") | |
+ def do_set_commission_and_recalulate(self): | |
+ """Change commission and recalculate commissions | |
+ """ | |
+ agent = self.agent_id | |
result = {} | |
v = {} | |
- if agent_id: | |
- agent = self.pool.get('sale.agent').browse(cr, uid, agent_id, context=context) | |
- v['commission_id'] = agent.commission.id | |
- agent_line = self.browse(cr, uid, ids, context=context) | |
- if agent_line: | |
- v['quantity'] = agent_line[0].invoice_line_id.price_subtotal * (agent.commission.fix_qty / 100.0) | |
- else: | |
- v['quantity'] = 0 | |
+ if self.agent_id: | |
+ self.commission_id = self.agent_id.commission | |
+ subtotal = self.invoice_line_id.price_subtotal | |
+ self.quantity = subtotal * (agent.commission.fix_qty / 100.0) | |
result['value'] = v | |
return result | |
- def onchange_commission_id(self, cr, uid, ids, agent_id, commission_id, context=None): | |
- """alerta al usuario sobre la comisión elegida""" | |
- if context is None: | |
- context = {} | |
- result = {} | |
- v = {} | |
- if commission_id: | |
- partner_commission = self.pool.get('commission').browse(cr, uid, commission_id, context=context) | |
- agent_line = self.browse(cr, uid, ids, context=context) | |
- v['quantity'] = agent_line[0].invoice_line_id.price_subtotal * (partner_commission.fix_qty / 100.0) | |
- result['value'] = v | |
- if partner_commission.sections and agent_id: | |
- agent = self.pool.get('sale.agent').browse(cr, uid, agent_id, context=context) | |
- if agent.commission.id != partner_commission.id: | |
- result['warning'] = { | |
- 'title': _('Fee installments!'), | |
- 'message': _('A commission has been assigned by sections that does not ' | |
- 'match that defined for the agent by default, so that these ' | |
- 'sections shall apply only on this bill.') | |
+ @api.onchange("commission_id") | |
+ def do_check_commission_and_recalculate(self): | |
+ """Recalculate commissions, check selected commission | |
+ and raise a warning when selected commission | |
+ is not the default provided for sale agent | |
+ and default partner commission have sections | |
+ """ | |
+ commission = self.commission_id | |
+ if commission: | |
+ # XXX: unused | |
+ # commission_obj = self.pool.get('commission') | |
+ agent_commission = self.agent_id.commission | |
+ subtotal = self.invoice_line_id.price_subtotal | |
+ self.quantity = subtotal * (agent_commission.fix_qty / 100.0) | |
+ | |
+ if self.agent_id and commission.sections: | |
+ if commission.id != agent_commission.id: | |
+ return { | |
+ "warning": { | |
+ "title": _('Fee installments!'), | |
+ "message": _( | |
+ "Selected commission has been assigned " | |
+ "by sections and it does not match " | |
+ "the one defined to the selected agent." | |
+ "These sections shall apply only on this bill." | |
+ ) | |
+ } | |
} | |
- return result | |
-class account_invoice_line(orm.Model): | |
- """Enlazamos las comisiones a la factura""" | |
+class account_invoice_line(models.Model): | |
+ """Relation between commissions and invoice""" | |
_inherit = "account.invoice.line" | |
- _columns = { | |
- 'commission_ids': fields.one2many('invoice.line.agent', 'invoice_line_id', 'Commissions', | |
- help="Commissions asociated to invoice line."), | |
- } | |
+ commission_ids = fields.One2many( | |
+ "invoice.line.agent", | |
+ "invoice_line_id", | |
+ string="Commissions", | |
+ help="Commissions asociated to invoice line." | |
+ ) | |
-class account_invoice(orm.Model): | |
+ | |
+class account_invoice(models.Model): | |
"""heredamos las facturas para añadirles el representante de venta""" | |
_inherit = "account.invoice" | |
- _columns = { | |
- 'agent_id': fields.many2one('sale.agent', 'Agent'), | |
- 'agent_code': fields.related('agent_id', 'code', readonly=True, type='char', string='Agent code'), | |
- 'country': fields.related('partner_id', 'country_id', readonly=True, type='many2one', string='Country', | |
- relation='res.country'), | |
- } | |
- | |
- def onchange_partner_id(self, cr, uid, ids, type, part, date_invoice=False, payment_term=False, | |
- partner_bank_id=False, company_id=False, context=None): | |
- """Al cambiar la empresa nos treamos el representante asociado a la empresa""" | |
+ | |
+ agent_id = fields.Many2one('sale.agent', 'Agent') | |
+ agent_code = fields.Char( | |
+ string="Agent code", | |
+ related="agent_id.code", | |
+ readonly=True, | |
+ | |
+ ) | |
+ country = fields.Many2one( | |
+ "res.country", | |
+ string="Country", | |
+ related="partner_id.country_id", | |
+ readonly=True | |
+ ) | |
+ | |
+ def onchange_partner_id(self, cr, uid, ids, type, part, | |
+ date_invoice=False, payment_term=False, | |
+ partner_bank_id=False, company_id=False, | |
+ context=None): | |
+ """Al cambiar la empresa nos treamos el representante | |
+ asociado a la empresa | |
+ """ | |
if context is None: | |
context = {} | |
- res = super(account_invoice, self).onchange_partner_id(cr, uid, ids, | |
- type, part, date_invoice, payment_term, partner_bank_id, company_id) | |
+ res = super(account_invoice, self).onchange_partner_id( | |
+ cr, uid, ids, | |
+ type, part, date_invoice, | |
+ payment_term, partner_bank_id, company_id | |
+ ) | |
if part and res.get('value', False): | |
- partner = self.pool.get('res.partner').browse(cr, uid, part, context=context) | |
+ partner_obj = self.pool.get('res.partner') | |
+ partner = partner_obj.browse(cr, uid, part, context=context) | |
if partner.commission_ids: | |
- res['value']['agent_id'] = partner.commission_ids[0].agent_id.id | |
+ agent_id = partner.commission_ids[0].agent_id.id | |
+ res['value']['agent_id'] = agent_id | |
return res | |
def _refund_cleanup_lines(self, cr, uid, lines, context=None): | |
- """ugly function to map all fields of account.invoice.line when creates refund invoice""" | |
+ """ugly function to map all fields of account.invoice.line | |
+ when creates refund invoice""" | |
if context is None: | |
context = {} | |
- res = super(account_invoice, self)._refund_cleanup_lines(cr, uid, lines, context=context) | |
+ res = super(account_invoice, self)._refund_cleanup_lines( | |
+ cr, uid, lines, context=context | |
+ ) | |
for line in res: | |
if 'commission_ids' in line[2]: | |
- line[2]['commission_ids'] = [(6, 0, line[2].get('commission_ids', [])), ] | |
+ commission_ids = [(6, 0, line[2].get('commission_ids', []))] | |
+ line[2]['commission_ids'] = commission_ids | |
return res | |
diff --git a/sale_commission/invoice_view.xml b/sale_commission/invoice_view.xml | |
index 8909bfd..7e25e27 100644 | |
--- a/sale_commission/invoice_view.xml | |
+++ b/sale_commission/invoice_view.xml | |
@@ -20,10 +20,12 @@ | |
<field name="model">invoice.line.agent</field> | |
<field name="arch" type="xml"> | |
<form string="Commissions and Agents" > | |
- <field name="agent_id" on_change="onchange_agent_id(agent_id)"/> | |
- <field name="commission_id" on_change="onchange_commission_id(agent_id, commission_id)" /> | |
- <field name="settled" /> | |
- <field name="quantity" readonly="1"/> | |
+ <group> | |
+ <field name="agent_id" /> | |
+ <field name="commission_id" /> | |
+ <field name="settled" /> | |
+ <field name="quantity" readonly="1"/> | |
+ </group> | |
</form> | |
</field> | |
</record> | |
@@ -34,38 +36,52 @@ | |
<field name="inherit_id" ref="account.view_invoice_line_form" /> | |
<field name="arch" type="xml"> | |
<field name="name" position="after"> | |
- <separator string="Commissions" colspan="2"/> | |
- <field name="commission_ids" colspan="2" nolabel="1"/> | |
- <!-- | |
- <separator string="Notes" colspan="2"/> | |
- <field colspan="2" name="note" nolabel="1"/> | |
- --> | |
- </field> | |
+ <separator string="Commissions" colspan="2"/> | |
+ <field name="commission_ids" colspan="2" nolabel="1"/> | |
+ <!-- BBB: Should it be removed? | |
+ <separator string="Notes" colspan="2"/> | |
+ <field colspan="2" name="note" nolabel="1"/> | |
+ --> | |
+ </field> | |
</field> | |
</record> | |
+ | |
<record id="invoice_supplier_form_add_agent_field" model="ir.ui.view"> | |
<field name="name">account.invoice.supplier.form.add_agent_field</field> | |
<field name="model">account.invoice</field> | |
<field name="inherit_id" ref="account.invoice_supplier_form"/> | |
<field name="arch" type="xml"> | |
+ <xpath expr="//field[@name='invoice_line']/tree" | |
+ position="attributes"> | |
+ <attribute name="editable" eval="False" /> | |
+ </xpath> | |
<field name="period_id" position="after"> | |
<field name="agent_id"/> | |
</field> | |
</field> | |
</record> | |
+ | |
<record id="invoice_form_add_agent_field" model="ir.ui.view"> | |
<field name="name">account.invoice.form.add_agent_field</field> | |
<field name="model">account.invoice</field> | |
<field name="inherit_id" ref="account.invoice_form"/> | |
<field name="arch" type="xml"> | |
+ <!-- BBB: this makes possible to edit/view each invoice line | |
+ in a popup form and also set/view sale agent information. | |
+ --> | |
+ <xpath expr="//field[@name='invoice_line']/tree" | |
+ position="attributes"> | |
+ <attribute name="editable" eval="False" /> | |
+ </xpath> | |
<field name="move_id" position="after"> | |
<field name="agent_id"/> | |
</field> | |
</field> | |
</record> | |
+ | |
<record id="invoice_form_add_code_country" model="ir.ui.view"> | |
<field name="name">account.invoice.form.add_code_country</field> | |
<field name="model">account.invoice</field> | |
@@ -79,4 +95,4 @@ | |
</record> | |
</data> | |
-</openerp> | |
\ No newline at end of file | |
+</openerp> | |
diff --git a/sale_commission/partner.py b/sale_commission/partner.py | |
index 5c90d1c..a445f24 100644 | |
--- a/sale_commission/partner.py | |
+++ b/sale_commission/partner.py | |
@@ -2,7 +2,8 @@ | |
############################################################################## | |
# | |
# OpenERP, Open Source Management Solution | |
-# Copyright (C) 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>). All Rights Reserved | |
+# Copyright (C) 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>). | |
+# All Rights Reserved | |
# $Id$ | |
# | |
# This program is free software: you can redistribute it and/or modify | |
@@ -19,21 +20,25 @@ | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# | |
############################################################################## | |
+from openerp import models, fields | |
-"""añadimos algún campo relacionado con el intrastat""" | |
-from osv import fields, orm | |
- | |
- | |
-class res_partner(orm.Model): | |
- """añadimos algún campo relacionado con elas comisiones""" | |
+class res_partner(models.Model): | |
+ """Add some fields related to commissions""" | |
_name = "res.partner" | |
_inherit = "res.partner" | |
- _columns = { | |
- 'commission_ids': fields.one2many('res.partner.agent', 'partner_id', 'Agents'), | |
- 'agent': fields.boolean('Creditor/Agent', | |
- help="If you check this field will be available as creditor or agent.") | |
- } | |
+ | |
+ commission_ids = fields.One2many( | |
+ "res.partner.agent", | |
+ "partner_id", | |
+ string="Agents" | |
+ ) | |
+ | |
+ agent = fields.Boolean( | |
+ string="Creditor/Agent", | |
+ help="If you check this field will be available as creditor or agent." | |
+ ) | |
+ | |
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: | |
diff --git a/sale_commission/partner_agent.py b/sale_commission/partner_agent.py | |
index d6e6111..89b0c90 100644 | |
--- a/sale_commission/partner_agent.py | |
+++ b/sale_commission/partner_agent.py | |
@@ -2,7 +2,8 @@ | |
############################################################################## | |
# | |
# OpenERP, Open Source Management Solution | |
-# Copyright (C) 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>). All Rights Reserved | |
+# Copyright (C) 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>). | |
+# All Rights Reserved | |
# $Id$ | |
# | |
# This program is free software: you can redistribute it and/or modify | |
@@ -19,71 +20,76 @@ | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# | |
############################################################################## | |
+from openerp import models, fields, api, _ | |
-"""objeto de comportamiento many2many que relaciona agentes o comerciales con partners""" | |
-from osv import fields, orm | |
-from tools.translate import _ | |
+class res_partner_agent(models.Model): | |
+ """This model relates sales agents to partnes | |
+ """ | |
+ _name = "res.partner.agent" | |
+ _rec_name = "agent_name" | |
+ partner_id = fields.Many2one( | |
+ "res.partner", | |
+ string="Partner", | |
+ required=True, | |
+ ondelete="cascade", | |
+ select=1 | |
+ ) | |
-class res_partner_agent(orm.Model): | |
- """objeto de comportamiento many2many que relaciona agentes o comerciales con partners""" | |
- _name = "res.partner.agent" | |
+ agent_id = fields.Many2one( | |
+ "sale.agent", | |
+ string="Agent", | |
+ required=True, | |
+ ondelete="cascade" | |
+ ) | |
- def name_get(self, cr, uid, ids, context=None): | |
- """devuelve como nombre del agente del partner el nombre del agente""" | |
- if context is None: | |
- context = {} | |
- return [(obj.id, obj.agent_id.name) for obj in self.browse(cr, uid, ids, context=context)] | |
+ agent_name = fields.Char( | |
+ string="Agent name", | |
+ related="agent_id.name" | |
+ ) | |
- def _get_partner_agents_to_update_from_sale_agents(self, cr, uid, ids, context=None): | |
- """ | |
- devuelve los ids de partner agents a actualizar desde el lanzamiento de un evento de actualización en agentes | |
- de ventas | |
- """ | |
- if context is None: | |
- context = {} | |
- agent_pool = self.pool.get('res.partner.agent') | |
- agent_obj_ids = [agent_obj_id.id for agent_obj_id in self.browse(cr, uid, ids, context=context)] | |
- return agent_pool.search(cr, uid, [('agent_id', 'in', agent_obj_ids)], context=context) | |
+ commission_id = fields.Many2one( | |
+ "commission", | |
+ string="Applied commission", | |
+ required=True, | |
+ ondelete="cascade" | |
+ ) | |
- _columns = { | |
- 'partner_id': fields.many2one('res.partner', 'Partner', required=True, ondelete='cascade', help='', select=1), | |
- 'agent_id': fields.many2one('sale.agent', 'Agent', required=True, ondelete='cascade', help=''), | |
- 'commission_id': fields.many2one('commission', 'Applied commission', required=True, ondelete='cascade', | |
- help=''), | |
- 'type': fields.related('agent_id', 'type', type="selection", | |
- selection=[('asesor', 'Adviser'), ('comercial', 'Commercial')], readonly=True, | |
- store={'sale.agent': (_get_partner_agents_to_update_from_sale_agents, ['type'], 10), | |
- 'res.partner.agent': (lambda self, cr, uid, ids, c={}: ids, None, 20)}) | |
- } | |
+ type = fields.Selection( | |
+ string="Type", | |
+ related="agent_id.type", | |
+ selection=[('asesor', 'Adviser'), ('comercial', 'Commercial')], | |
+ readonly=True, | |
+ store=True | |
+ ) | |
- def onchange_agent_id(self, cr, uid, ids, agent_id, context=None): | |
- """al cambiar el agente cargamos sus comisión""" | |
- result = {} | |
- v = {} | |
- if agent_id: | |
- agent = self.pool.get('sale.agent').browse(cr, uid, agent_id, context=context) | |
- v['commission_id'] = agent.commission.id | |
- result['value'] = v | |
- return result | |
+ @api.onchange("agent_id") | |
+ def do_set_default_commission(self): | |
+ """Set default commission when sale agent has changed""" | |
+ self.commission_id = self.agent_id.commission | |
- def onchange_commission_id(self, cr, uid, ids, agent_id=False, commission_id=False, context=None): | |
- """al cambiar la comisión comprobamos la selección""" | |
- if context is None: | |
- context = {} | |
- result = {} | |
- if commission_id: | |
- partner_commission = self.pool.get('commission').browse(cr, uid, commission_id, context=context) | |
- if partner_commission.sections and agent_id: | |
- agent = self.pool.get('sale.agent').browse(cr, uid, agent_id, context=context) | |
- if agent.commission.id != partner_commission.id: | |
- result['warning'] = { | |
- 'title': _('Fee installments!'), | |
- 'message': _('A commission has been assigned by sections that does not ' | |
- 'match that defined for the agent by default, so that these ' | |
- 'sections shall apply only on this bill.') | |
+ @api.onchange("commission_id") | |
+ def do_check_commission(self): | |
+ """Check selected commission and raise a warning | |
+ when selected commission is not the default provided for sale agent | |
+ and default partner commission have sections | |
+ """ | |
+ commission = self.commission_id | |
+ if commission.id: | |
+ agent_commission = self.agent_id.commission | |
+ if self.agent_id and commission.sections: | |
+ if commission.id != agent_commission.id: | |
+ return { | |
+ "warning": { | |
+ "title": _('Fee installments!'), | |
+ "message": _( | |
+ "Selected commission has been assigned " | |
+ "by sections and it does not match " | |
+ "the one defined to the selected agent." | |
+ "These sections shall apply only on this bill." | |
+ ) | |
+ } | |
} | |
- return result | |
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: | |
diff --git a/sale_commission/partner_agent_view.xml b/sale_commission/partner_agent_view.xml | |
index 478b6a4..3fd3e19 100644 | |
--- a/sale_commission/partner_agent_view.xml | |
+++ b/sale_commission/partner_agent_view.xml | |
@@ -2,25 +2,27 @@ | |
<openerp> | |
<data> | |
- <record model="ir.ui.view" id="view_partner_agent_comision_tree"> | |
- <field name="name">partner.agent.comision.tree.inherit</field> | |
+ <record model="ir.ui.view" id="view_partner_agent_commission_tree"> | |
+ <field name="name">partner.agent.commission.tree.inherit</field> | |
<field name="model">res.partner.agent</field> | |
<field name="arch" type="xml"> | |
<tree string="Agents"> | |
- <field name="partner_id"/> | |
- <field name="agent_id"/> | |
- <field name="commission_id"/> | |
+ <field name="partner_id" /> | |
+ <field name="agent_id" /> | |
+ <field name="commission_id" /> | |
</tree> | |
</field> | |
</record> | |
- <record model="ir.ui.view" id="view_partner_agent_comision_form"> | |
- <field name="name">partner.agent.comision.form.inherit</field> | |
+ <record model="ir.ui.view" id="view_partner_agent_commission_form"> | |
+ <field name="name">partner.agent.commission.form.inherit</field> | |
<field name="model">res.partner.agent</field> | |
<field name="arch" type="xml"> | |
<form string="Agents"> | |
- <field name="agent_id" on_change="onchange_agent_id(agent_id)"/> | |
- <field name="commission_id" on_change="onchange_commission_id(agent_id,commission_id)"/> | |
+ <group> | |
+ <field name="agent_id" /> | |
+ <field name="commission_id" /> | |
+ </group> | |
</form> | |
</field> | |
</record> | |
diff --git a/sale_commission/partner_view.xml b/sale_commission/partner_view.xml | |
index e87308a..ef5af76 100644 | |
--- a/sale_commission/partner_view.xml | |
+++ b/sale_commission/partner_view.xml | |
@@ -1,15 +1,15 @@ | |
<?xml version="1.0"?> | |
<openerp> | |
<data> | |
- | |
+ | |
<record id="view_partner_form_add_agent" model="ir.ui.view"> | |
<field name="name">res.partner.form.add_agent</field> | |
<field name="model">res.partner</field> | |
- <field name="inherit_id" ref="base.view_partner_form"/> | |
+ <field name="inherit_id" ref="base.view_partner_form" /> | |
<field name="priority" eval="18"/> | |
<field name="arch" type="xml"> | |
<xpath expr="//page[@string='Sales & Purchases']//field[@name='supplier']" position="after"> | |
- <field name="agent" string="Consultancy"/> | |
+ <field name="agent" string="Consultancy" /> | |
</xpath> | |
</field> | |
</record> | |
@@ -17,13 +17,16 @@ | |
<record id="view_partner_form_add_agents" model="ir.ui.view"> | |
<field name="name">res.partner.form.add_agents</field> | |
<field name="model">res.partner</field> | |
- <field name="inherit_id" ref="view_partner_form_add_agent"/> | |
+ <field name="inherit_id" | |
+ ref="view_partner_form_add_agent" /> | |
<field name="arch" type="xml"> | |
<field name="user_id" position="after"> | |
- <field string="Agents/Consultancy" name="commission_ids"> | |
- <tree string="Agents and Commissions" editable="top"> | |
- <field name="agent_id" on_change="onchange_agent_id(agent_id)"/> | |
- <field name="commission_id" on_change="onchange_commission_id(agent_id,commission_id)"/> | |
+ <field string="Agents/Consultancy" | |
+ name="commission_ids"> | |
+ <tree string="Agents and Commissions" | |
+ editable="top"> | |
+ <field name="agent_id" /> | |
+ <field name="commission_id" /> | |
</tree> | |
</field> | |
</field> | |
diff --git a/sale_commission/product_view.xml b/sale_commission/product_view.xml | |
index 7a9ac93..05f834e 100644 | |
--- a/sale_commission/product_view.xml | |
+++ b/sale_commission/product_view.xml | |
@@ -1,16 +1,22 @@ | |
<?xml version="1.0"?> | |
<openerp> | |
<data> | |
- | |
- <record id="product_normal_form_view_exclude_commisions" model="ir.ui.view"> | |
+ | |
+ <record id="product_normal_form_view_exclude_commissions" | |
+ model="ir.ui.view"> | |
<field name="name">product.normal.form.exclude_commissions</field> | |
<field name="model">product.product</field> | |
<field name="inherit_id" ref="product.product_normal_form_view"/> | |
<field name="arch" type="xml"> | |
- <field name="description_sale" position="after"> | |
- <group> | |
- <field name="commission_exent"/> | |
- </group> | |
+ <field name="sale_ok" position="after"> | |
+ <div class="oe_left" | |
+ name="options" | |
+ groups="base.group_user"> | |
+ <div> | |
+ <field name="commission_exent"/> | |
+ <label for="commission_exent"/> | |
+ </div> | |
+ </div> | |
</field> | |
</field> | |
</record> | |
diff --git a/sale_commission/report/settlement_report.rml b/sale_commission/report/settlement_report.rml | |
deleted file mode 100644 | |
index 32f0c80..0000000 | |
--- a/sale_commission/report/settlement_report.rml | |
+++ /dev/null | |
@@ -1,238 +0,0 @@ | |
-<?xml version="1.0"?> | |
-<document filename="test.pdf"> | |
- <template pageSize="(595.0,842.0)" title="Test" author="Martin Simon" allowSplitting="20"> | |
- <pageTemplate id="first"> | |
- <frame id="first" x1="0.0" y1="57.0" width="538" height="728"/> | |
- </pageTemplate> | |
- </template> | |
- <stylesheet> | |
- <blockTableStyle id="Standard_Outline"> | |
- <blockAlignment value="LEFT"/> | |
- <blockValign value="TOP"/> | |
- </blockTableStyle> | |
- <blockTableStyle id="Table_Address_detail"> | |
- <blockAlignment value="LEFT"/> | |
- <blockValign value="TOP"/> | |
- </blockTableStyle> | |
- <blockTableStyle id="Table_Title_String"> | |
- <blockAlignment value="LEFT"/> | |
- <blockValign value="TOP"/> | |
- </blockTableStyle> | |
- <blockTableStyle id="Header_Order_Reference_Tbl"> | |
- <blockAlignment value="LEFT"/> | |
- <blockValign value="TOP"/> | |
- <lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="0,0" stop="0,-1"/> | |
- <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="0,0" stop="0,0"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,-1" stop="0,-1"/> | |
- <lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="1,0" stop="1,-1"/> | |
- <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="1,0" stop="1,0"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="1,-1" stop="1,-1"/> | |
- <lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="2,0" stop="2,-1"/> | |
- <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="2,0" stop="2,0"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="2,-1" stop="2,-1"/> | |
- <lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="3,0" stop="3,-1"/> | |
- <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="3,0" stop="3,0"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="3,-1" stop="3,-1"/> | |
- <lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="4,0" stop="4,-1"/> | |
- <lineStyle kind="LINEAFTER" colorName="#e6e6e6" start="4,0" stop="4,-1"/> | |
- <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="4,0" stop="4,0"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="4,-1" stop="4,-1"/> | |
- </blockTableStyle> | |
- <blockTableStyle id="Content_Order_Reference_Table"> | |
- <blockAlignment value="LEFT"/> | |
- <blockValign value="TOP"/> | |
- <lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="0,0" stop="0,-1"/> | |
- <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="0,0" stop="0,0"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,-1" stop="0,-1"/> | |
- <lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="1,0" stop="1,-1"/> | |
- <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="1,0" stop="1,0"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="1,-1" stop="1,-1"/> | |
- <lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="2,0" stop="2,-1"/> | |
- <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="2,0" stop="2,0"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="2,-1" stop="2,-1"/> | |
- <lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="3,0" stop="3,-1"/> | |
- <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="3,0" stop="3,0"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="3,-1" stop="3,-1"/> | |
- <lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="4,0" stop="4,-1"/> | |
- <lineStyle kind="LINEAFTER" colorName="#e6e6e6" start="4,0" stop="4,-1"/> | |
- <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="4,0" stop="4,0"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="4,-1" stop="4,-1"/> | |
- </blockTableStyle> | |
- <blockTableStyle id="Move_Line_Header"> | |
- <blockAlignment value="LEFT"/> | |
- <blockValign value="TOP"/> | |
- <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="0,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#000000" start="1,-1" stop="1,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#000000" start="2,-1" stop="2,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#000000" start="3,-1" stop="3,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#000000" start="4,-1" stop="4,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#000000" start="5,-1" stop="5,-1"/> | |
- </blockTableStyle> | |
- <blockTableStyle id="Move_Line_Contect_Assign_State"> | |
- <blockAlignment value="LEFT"/> | |
- <blockValign value="TOP"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,-1" stop="0,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="1,-1" stop="1,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="2,-1" stop="2,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="3,-1" stop="3,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="4,-1" stop="4,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="5,-1" stop="5,-1"/> | |
- </blockTableStyle> | |
- <blockTableStyle id="Move_Line_Content_Other_State"> | |
- <blockAlignment value="LEFT"/> | |
- <blockValign value="TOP"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,-1" stop="0,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="1,-1" stop="1,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="2,-1" stop="2,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="3,-1" stop="3,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="4,-1" stop="4,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="5,-1" stop="5,-1"/> | |
- </blockTableStyle> | |
- <blockTableStyle id="Table6"> | |
- <blockAlignment value="LEFT"/> | |
- <blockValign value="TOP"/> | |
- <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="0,-1" stop="0,-1"/> | |
- <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="1,-1" stop="1,-1"/> | |
- <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="2,-1" stop="2,-1"/> | |
- <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="3,-1" stop="3,-1"/> | |
- <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="4,-1" stop="4,-1"/> | |
- <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="5,-1" stop="5,-1"/> | |
- <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="6,-1" stop="6,-1"/> | |
- <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="7,-1" stop="7,-1"/> | |
- <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="8,-1" stop="8,-1"/> | |
- <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="9,-1" stop="9,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,-1" stop="0,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="1,-1" stop="1,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="2,-1" stop="2,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="3,-1" stop="3,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="4,-1" stop="4,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="5,-1" stop="5,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="6,-1" stop="6,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="7,-1" stop="7,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="8,-1" stop="8,-1"/> | |
- <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="9,-1" stop="9,-1"/> | |
- </blockTableStyle> | |
- <blockTableStyle id="Table7"> | |
- <blockAlignment value="LEFT"/> | |
- <blockValign value="TOP"/> | |
- </blockTableStyle> | |
- <blockTableStyle id="Table8"> | |
- <blockAlignment value="CENTER"/> | |
- <blockValign value="MIDDLE"/> | |
- <lineStyle kind="BOX" colorName="#000000" thickness="1" start="0,0" stop="-1,0" /> | |
- </blockTableStyle> | |
- <initialize> | |
- <paraStyle name="all" alignment="justify"/> | |
- </initialize> | |
- <paraStyle name="Standard" fontName="Helvetica"/> | |
- <paraStyle name="Heading" fontName="Helvetica" fontSize="14.0" leading="17" spaceBefore="12.0" spaceAfter="6.0"/> | |
- <paraStyle name="Text body" fontName="Helvetica" spaceBefore="0.0" spaceAfter="6.0"/> | |
- <paraStyle name="List" fontName="Helvetica" spaceBefore="0.0" spaceAfter="6.0"/> | |
- <paraStyle name="Caption" fontName="Helvetica-Oblique" fontSize="12.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/> | |
- <paraStyle name="Index" fontName="Helvetica"/> | |
- <paraStyle name="terp_header" fontName="Helvetica-Bold" fontSize="12.0" leading="15" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> | |
- <paraStyle name="terp_header_Centre" fontName="Helvetica-Bold" fontSize="12.0" leading="15" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/> | |
- <paraStyle name="terp_default_8" fontName="Helvetica" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> | |
- <paraStyle name="terp_default_Bold_8" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> | |
- <paraStyle name="terp_default_Bold" rightIndent="0.0" leftIndent="20.0" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> | |
- <paraStyle name="terp_tblheader_Details" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> | |
- <paraStyle name="terp_tblheader_Details_Centre" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/> | |
- <paraStyle name="terp_default_Centre_8" fontName="Helvetica" fontSize="8.0" leading="10" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/> | |
- <paraStyle name="terp_default_Centre_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/> | |
- <paraStyle name="terp_tblheader_General" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/> | |
- <paraStyle name="terp_tblheader_General_Centre" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/> | |
- <paraStyle name="Table Contents" fontName="Helvetica"/> | |
- <paraStyle name="Footer" fontName="Helvetica"/> | |
- <paraStyle name="Table Heading" fontName="Helvetica" alignment="CENTER"/> | |
- <paraStyle name="Horizontal Line" fontName="Helvetica" fontSize="6.0" leading="8" spaceBefore="0.0" spaceAfter="14.0"/> | |
- <paraStyle name="Heading 9" fontName="Helvetica-Bold" fontSize="75%" leading="NaN" spaceBefore="12.0" spaceAfter="6.0"/> | |
- <paraStyle name="terp_tblheader_General_Right" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/> | |
- <paraStyle name="terp_tblheader_Details_Right" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/> | |
- <paraStyle name="terp_default_Right_8" fontName="Helvetica" fontSize="8.0" leading="10" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/> | |
- <paraStyle name="terp_header_Right" fontName="Helvetica-Bold" fontSize="15.0" leading="19" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> | |
- <paraStyle name="terp_default_address" fontName="Helvetica" fontSize="10.0" leading="13" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> | |
- <paraStyle name="terp_default_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> | |
- <paraStyle name="terp_default_Bold_9" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> | |
- <paraStyle name="terp_default_Right_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/> | |
- <paraStyle name="terp_default_2" fontName="Helvetica" fontSize="2.0" leading="3" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> | |
- <paraStyle name="terp_default_5cm_Above_Space" fontName="Helvetica" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="6.0" spaceAfter="0.0"/> | |
- <paraStyle name="terp_default_1cm_above_space" fontName="Helvetica" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="3.0" spaceAfter="0.0"/> | |
- <paraStyle name="terp_default_Italic" rightIndent="0.0" leftIndent="20.0" fontName="Helvetica-Oblique" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> | |
- </stylesheet> | |
- <images/> | |
- <story> | |
- <para style="terp_default_8">[[ repeatIn(objects, 's')]] </para> | |
- <section> | |
- <para style="terp_default_8">[[ repeatIn(s.settlement_agent_id, 'agent') ]] </para> | |
- <para style="terp_default_80">[[ agent.agent_id.partner_id and setLang(agent.agent_id.partner_id.lang) ]]</para> | |
- <blockTable colWidths="538.0" style="Table_Title_String"> | |
- <tr> | |
- <td> | |
- <para style="terp_header">SETTLEMENT: [[ (s.date_from and s.date_to) and formatLang(s.date_from, date=True) + '//' + formatLang(s.date_to, date=True) or s.name ]]</para> | |
- </td> | |
- </tr> | |
- </blockTable> | |
- <para style="terp_default_5cm_Above_Space"> | |
- <font color="white"> </font> | |
- </para> | |
- <blockTable colWidths="538.0" style="Table_Title_String"> | |
- <tr> | |
- <td> | |
- <para style="terp_default_Bold_9">AGENT: [[ agent.agent_id.name ]]</para> | |
- </td> | |
- </tr> | |
- </blockTable> | |
- <para style="terp_default_5cm_Above_Space"> | |
- <font color="white"> </font> | |
- </para> | |
- <blockTable colWidths="135.0,135.0,124.0,120.0" style="Header_Order_Reference_Tbl"> | |
- <tr> | |
- <td> | |
- <para style="terp_tblheader_General_Centre">INVOICE NO [[not agent.invoices and removeParentNode('blockTable')]]</para> | |
- </td> | |
- <td> | |
- <para style="terp_tblheader_General_Centre">INVOICE DATE</para> | |
- </td> | |
- <td> | |
- <para style="terp_tblheader_General_Centre">AMOUNT INVOICED</para> | |
- </td> | |
- <td> | |
- <para style="terp_tblheader_General_Centre">AMOUNT SETTLED</para> | |
- </td> | |
- </tr> | |
- </blockTable> | |
- | |
- <section> | |
- <para style="terp_default_80">[[repeatIn(agent.invoices,'invoice')]]</para> | |
- <blockTable colWidths="135.0,135.0,124.0,120.0" style="Content_Order_Reference_Table"> | |
- <tr> | |
- <td> | |
- <para style="terp_default_Centre_8">[[ invoice.invoice_number or '' ]]</para> | |
- </td> | |
- <td> | |
- <para style="terp_default_Centre_8">[[ invoice.invoice_date or '' ]]</para> | |
- </td> | |
- <td> | |
- <para style="terp_default_Centre_8">[[ formatLang(invoice.invoice_amount or 0.0) ]] [[ invoice.currency_id and invoice.currency_id.code or '']]</para> | |
- </td> | |
- <td> | |
- <para style="terp_default_Centre_8">[[ formatLang(invoice.settled_amount or 0.0) ]] [[ invoice.currency_id and invoice.currency_id.code or '']]</para> | |
- </td> | |
- </tr> | |
- </blockTable> | |
- </section> | |
- <blockTable colWidths="394.0,120.0" style="Table7"> | |
- <tr> | |
- <td> | |
- <para style="terp_default_Right_8">TOTAL : [[ not agent.invoices and removeParentNode('blockTable') ]]</para> | |
- </td> | |
- <td> | |
- <para style="terp_default_Centre_8">[[ formatLang(agent.total or 0.0) ]]</para> | |
- </td> | |
- </tr> | |
- </blockTable> | |
- <nextFrame/> | |
- </section> | |
- | |
- </story> | |
-</document> | |
\ No newline at end of file | |
diff --git a/sale_commission/sale_agent.py b/sale_commission/sale_agent.py | |
index ad0c8f8..d52c01a 100644 | |
--- a/sale_commission/sale_agent.py | |
+++ b/sale_commission/sale_agent.py | |
@@ -2,7 +2,8 @@ | |
############################################################################## | |
# | |
# OpenERP, Open Source Management Solution | |
-# Copyright (C) 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>). All Rights Reserved | |
+# Copyright (C) 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>). | |
+# All Rights Reserved | |
# $Id$ | |
# | |
# This program is free software: you can redistribute it and/or modify | |
@@ -19,78 +20,139 @@ | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# | |
############################################################################## | |
+from openerp import models, fields | |
-from osv import fields, orm | |
- | |
-class commission(orm.Model): | |
- """Objeto comisión""" | |
+class commission(models.Model): | |
+ """Object commission""" | |
_name = "commission" | |
_description = "Commission" | |
- _columns = { | |
- 'name': fields.char('Name', size=64, required=True), | |
- 'type': fields.selection((('fijo', 'Fix percentage'), ('tramos', 'By sections')), 'Type', required=True), | |
- 'fix_qty': fields.float('Fix Percentage'), | |
- 'sections': fields.one2many('commission.section', 'commission_id', 'Sections') | |
- } | |
- _defaults = { | |
- 'type': 'fijo', | |
- } | |
+ | |
+ name = fields.Char('Name', required=True) | |
+ | |
+ type = fields.Selection( | |
+ (("fijo", "Fix percentage"), ("tramos", "By sections")), | |
+ string="Type", | |
+ required=True, | |
+ default="fijo" | |
+ ) | |
+ | |
+ fix_qty = fields.Float(string="Fix Percentage") | |
+ | |
+ sections = fields.One2many( | |
+ "commission.section", | |
+ "commission_id", | |
+ string="Sections" | |
+ ) | |
def calcula_tramos(self, cr, uid, ids, base, context=None): | |
if context is None: | |
context = {} | |
commission = self.browse(cr, uid, ids, context=context)[0] | |
- #Cálculo de tramos | |
+ # Cálculo de tramos | |
for section in commission.sections: | |
- if base >= section.commission_from and (base < section.commission_until or section.commission_until == 0): | |
+ if base >= section.commission_from and ( | |
+ base < section.commission_until or | |
+ section.commission_until == 0): | |
res = base * section.percent / 100.0 | |
return res | |
return 0.0 | |
-class commission_section(orm.Model): | |
- """periodo de las comisiones""" | |
+class commission_section(models.Model): | |
+ """Commission section""" | |
_name = "commission.section" | |
_description = "Commission section" | |
- _columns = { | |
- 'commission_from': fields.float('From'), | |
- 'commission_until': fields.float('Until'), | |
- 'percent': fields.float('Percent'), | |
- 'commission_id': fields.many2one('commission', 'Commission') | |
- } | |
+ commission_from = fields.Float(string="From") | |
+ commission_until = fields.Float(string="Until") | |
-class sale_agent(orm.Model): | |
- """Agente de ventas""" | |
+ percent = fields.Float(string="Percent") | |
+ | |
+ commission_id = fields.Many2one( | |
+ "commission", | |
+ string="Commission" | |
+ ) | |
+ | |
+ | |
+class sale_agent(models.Model): | |
+ """Sale agents""" | |
_name = "sale.agent" | |
_description = "Sale agent" | |
- _columns = { | |
- 'name': fields.char('Saleagent Name', size=125, required=True), | |
- 'type': fields.selection((('asesor', 'Adviser'), ('comercial', 'Commercial')), 'Type', required=True), | |
- 'partner_id': fields.many2one('res.partner', 'Partner', ondelete='cascade', | |
- help='Associated partner, is necessary for income invoices.'), | |
- 'code': fields.related('partner_id', 'ref', string='Code', readonly=True, type='char', | |
- help='Se obtiene del código de la empresa relacionada'), | |
- 'employee_id': fields.many2one('hr.employee', 'Associated Employee', | |
- help='Employee associated to agent, is necessary for set an employee ' | |
- 'to settle commissions in wage.'), | |
- 'customer': fields.one2many('res.partner.agent', 'agent_id', 'Customer', readonly=True), | |
- 'commission': fields.many2one('commission', 'Commission by default', required=True), | |
- 'settlement': fields.selection((('m', 'Monthly'), ('t', 'Quarterly'), ('s', 'Semiannual'), ('a', 'Annual')), | |
- 'Period settlement', required=True), | |
- 'active': fields.boolean('Active'), | |
- 'retention_id': fields.many2one('account.tax', 'Applied retention'), | |
- 'settlement_ids': fields.one2many('settlement.agent', 'agent_id', 'Settlements executed', readonly=True) | |
- } | |
- _defaults = { | |
- 'active': True, | |
- 'type': 'asesor', | |
- } | |
+ | |
+ name = fields.Char( | |
+ string="Sale agent Name", | |
+ required=True | |
+ ) | |
+ | |
+ type = fields.Selection( | |
+ (("asesor", "Adviser"), ("comercial", "Commercial")), | |
+ string="Type", | |
+ required=True, | |
+ default="asesor" | |
+ ) | |
+ | |
+ partner_id = fields.Many2one( | |
+ "res.partner", | |
+ string="Partner", | |
+ ondelete="cascade", | |
+ help="Associated partner, is necessary for income invoices." | |
+ ) | |
+ | |
+ code = fields.Char( | |
+ string="Code", | |
+ related="partner_id.ref", | |
+ readonly=True, | |
+ help="Related company code" | |
+ ) | |
+ | |
+ employee_id = fields.Many2one( | |
+ "hr.employee", | |
+ string="Associated Employee", | |
+ help="Employee associated to agent, is necessary for set an employee " | |
+ "to settle commissions in wage." | |
+ ) | |
+ | |
+ customer = fields.One2many( | |
+ "res.partner.agent", | |
+ "agent_id", | |
+ string="Customer", | |
+ readonly=True | |
+ ) | |
+ | |
+ commission = fields.Many2one( | |
+ "commission", | |
+ string="Commission by default", | |
+ required=True | |
+ ) | |
+ | |
+ settlement = fields.Selection( | |
+ ( | |
+ ("m", "Monthly"), ("t", "Quarterly"), | |
+ ("s", "Semi-annual"), ("a", "Annual") | |
+ ), | |
+ string="Settlement period", | |
+ default="m", | |
+ required=True | |
+ ) | |
+ | |
+ active = fields.Boolean(string="Active", default=True) | |
+ | |
+ retention_id = fields.Many2one( | |
+ "account.tax", | |
+ string="Applied retention" | |
+ ) | |
+ | |
+ settlement_ids = fields.One2many( | |
+ "settlement.agent", | |
+ "agent_id", | |
+ string="Settlements executed", | |
+ readonly=True | |
+ ) | |
def calcula_tramos(self, cr, uid, ids, base, context=None): | |
"""calcula los tramos por factura""" | |
@@ -98,5 +160,3 @@ class sale_agent(orm.Model): | |
context = {} | |
agente = self.browse(cr, uid, ids, context=context)[0] | |
return agente.commission.calcula_tramos(base) | |
- | |
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: | |
diff --git a/sale_commission/sale_agent_demo.xml b/sale_commission/sale_agent_demo.xml | |
index 3b8fcfc..aec1161 100644 | |
--- a/sale_commission/sale_agent_demo.xml | |
+++ b/sale_commission/sale_agent_demo.xml | |
@@ -1,58 +1,61 @@ | |
<?xml version="1.0"?> | |
<openerp> | |
<data> | |
- <record id="res_partner_sale_agent" model="res.partner"> | |
- <field name="name">Pritesh Sales Agent</field> | |
+ <record id="demo_commission" model="commission"> | |
+ <field name="name">10% fixed commission</field> | |
+ <field name="fix_qty">10.0</field> | |
</record> | |
- <record id="res_partner_address_pritesh" model="res.partner.address"> | |
+ <record id="res_partner_sale_agent" model="res.partner"> | |
+ <field name="name">Pritesh Sales Agent</field> | |
<field name="city">Ahmedabad</field> | |
- <field name="name">Defalt Agent Pritesh</field> | |
<field name="zip">380007</field> | |
- <field name="title">M.</field> | |
- <field name="country_id" model="res.country" search="[('name','=','India')]"/> | |
+ <field name="country_id" | |
+ model="res.country" | |
+ search="[('name','=','India')]" /> | |
<field name="street">56 Beijing street</field> | |
- <field name="type">default</field> | |
- <field name="partner_id" ref="res_partner_sale_agent"/> | |
</record> | |
- | |
- <record model="sale.agent" id="saleagent_parnter"> | |
+ <record id="demo_saleagent" model="sale.agent"> | |
<field name="name">Pritesh Sales Agent</field> | |
- <field name="partner_id" search="[('name','=','Pritesh Sales Agent')]" /> | |
+ <field name="commission" ref="demo_commission" /> | |
+ <field name="partner_id" ref="res_partner_sale_agent" /> | |
</record> | |
- | |
<record id="res_partner_eiffel" model="res.partner"> | |
<field name="name">Eiffel pvt ltd</field> | |
- <field name="agent_id" search="[('name','=','Pritesh Sales Agent')]" /> | |
- </record> | |
- | |
- <record id="res_partner_address_eiffel" model="res.partner.address"> | |
<field name="city">Ahmedabad</field> | |
<field name="name">Eiffel India</field> | |
<field name="zip">380007</field> | |
- <field name="title">M.</field> | |
- <field name="country_id" model="res.country" search="[('name','=','India')]"/> | |
+ <field name="country_id" | |
+ model="res.country" | |
+ search="[('name','=','India')]" /> | |
<field name="street">Wall Street 2</field> | |
- <field name="type">default</field> | |
- <field name="partner_id" ref="res_partner_eiffel"/> | |
+ <!-- <field name="agent_id" ref="saleagent_partner" /> --> | |
</record> | |
<record id="res_partner_tiny" model="res.partner"> | |
<field name="name">Tiny Belgium</field> | |
- <field name="agent_id" search="[('name','=','Pritesh Sales Agent')]" /> | |
- </record> | |
- | |
- <record id="res_partner_address_tiny" model="res.partner.address"> | |
<field name="city">Belgium</field> | |
<field name="name">Tiny Belgium</field> | |
<field name="zip">2457</field> | |
- <field name="title">M.</field> | |
- <field name="country_id" model="res.country" search="[('name','=','India')]"/> | |
+ <field name="country_id" | |
+ model="res.country" | |
+ search="[('name','=','India')]" /> | |
<field name="street">Belgium Gao</field> | |
- <field name="type">default</field> | |
- <field name="partner_id" ref="res_partner_tiny"/> | |
+ <!-- <field name="agent_id" ref="saleagent_partner" /> --> | |
+ </record> | |
+ | |
+ <record id="res_partner_agent_1" model="res.partner.agent"> | |
+ <field name="partner_id" ref="res_partner_tiny" /> | |
+ <field name="agent_id" ref="demo_saleagent" /> | |
+ <field name="commission_id" ref="demo_commission" /> | |
+ </record> | |
+ | |
+ <record id="res_partner_agent_2" model="res.partner.agent"> | |
+ <field name="partner_id" ref="res_partner_eiffel" /> | |
+ <field name="agent_id" ref="demo_saleagent" /> | |
+ <field name="commission_id" ref="demo_commission" /> | |
</record> | |
</data> | |
diff --git a/sale_commission/sale_agent_view.xml b/sale_commission/sale_agent_view.xml | |
index 3ec0832..c69112a 100644 | |
--- a/sale_commission/sale_agent_view.xml | |
+++ b/sale_commission/sale_agent_view.xml | |
@@ -1,23 +1,24 @@ | |
<?xml version="1.0"?> | |
<openerp> | |
<data> | |
- | |
-<!-- | |
- ======================= | |
- Saleagent Information | |
- ======================= | |
- --> | |
+ | |
+ <!-- | |
+ ====================== | |
+ Sale agent Information | |
+ ====================== | |
+ --> | |
+ | |
<record model="ir.ui.view" id="view_saleagent_tree"> | |
<field name="name">saleagent.info.tree</field> | |
<field name="model">sale.agent</field> | |
<field name="arch" type="xml"> | |
- <tree string="Saleagent"> | |
+ <tree string="Sale Agent"> | |
<field name="code" /> | |
<field name="name" /> | |
- <field name="active"/> | |
<field name="partner_id" /> | |
- <field name="commission"/> | |
- <field name="settlement"/> | |
+ <field name="commission" /> | |
+ <field name="settlement" /> | |
+ <field name="active" /> | |
</tree> | |
</field> | |
</record> | |
@@ -30,20 +31,25 @@ | |
<group> | |
<group> | |
<group> | |
- | |
- <field name="name"/> | |
- <field name="type"/> | |
+ <field name="name" /> | |
+ <field name="type" /> | |
</group> | |
<group> | |
- <field name="code"/> | |
- <field name="active"/> | |
+ <field name="code" /> | |
+ <field name="active" /> | |
</group> | |
</group> | |
- <group string="Related entity or employee" colspan="2"> | |
- <field attrs="{'required':[('type','=','asesor')], 'invisible':[('type','!=','asesor')]}" domain="[('agent','=',True)]" name="partner_id" select="2"/> | |
- <field attrs="{'required':[('type','=','comercial')], 'invisible':[('type','!=','comercial')]}" name="employee_id" select="2"/> | |
+ <group string="Related entity or employee" | |
+ colspan="2"> | |
+ <field name="partner_id" | |
+ attrs="{'required':[('type','=','asesor')], 'invisible':[('type','!=','asesor')]}" | |
+ domain="[('agent','=',True)]" | |
+ select="2" /> | |
+ <field name="employee_id" | |
+ attrs="{'required':[('type','=','comercial')], 'invisible':[('type','!=','comercial')]}" | |
+ select="2" /> | |
</group> | |
- </group> | |
+ </group> | |
<notebook colspan="4"> | |
<page string="Commission"> | |
<group> | |
@@ -51,55 +57,67 @@ | |
</group> | |
<group> | |
<field name="commission"/> | |
- <field domain="[('parent_id','=',False),('type_tax_use','<>','purchase')]" name="retention_id"/> | |
+ <field name="retention_id" | |
+ domain="[('parent_id','=',False),('type_tax_use','<>','purchase')]" | |
+ /> | |
</group> | |
</page> | |
<page string="Customer assigned"> | |
- <field colspan="4" name="customer" nolabel="1" readonly="1"/> | |
+ <field colspan="4" name="customer" | |
+ nolabel="1" readonly="1" /> | |
</page> | |
<page string="Settlements executed"> | |
- <field colspan="4" name="settlement_ids" nolabel="1" readonly="1"/> | |
+ <field name="settlement_ids" nolabel="1" | |
+ colspan="4" readonly="1" /> | |
</page> | |
</notebook> | |
</form> | |
</field> | |
</record> | |
- <record id="view_sale_agen_search model" model="ir.ui.view"> | |
+ | |
+ <record id="view_sale_agent_search" model="ir.ui.view"> | |
<field name="name">commission.sale.agent.search</field> | |
<field name="model">sale.agent</field> | |
<field name="arch" type="xml"> | |
<search string="Search Agent"> | |
- <group> | |
- <filter icon="terp-personal" string="Commercial" domain="[('type','=','comercial')]"/> | |
- <filter icon="terp-personal" string="Adviser" domain="[('type','=','asesor')]"/> | |
- <field name="code"/> | |
- <field name="name"/> | |
- <field name="commission"/> | |
- <field name="settlement"/> | |
+ <field name="code"/> | |
+ <field name="name"/> | |
+ <field name="commission"/> | |
+ <field name="settlement"/> | |
+ | |
+ <group expand="0" string="Filter by..."> | |
+ <filter icon="terp-personal" | |
+ string="Commercial" | |
+ domain="[('type','=','comercial')]" /> | |
+ <filter icon="terp-personal" | |
+ string="Adviser" | |
+ domain="[('type','=','asesor')]" /> | |
</group> | |
- <newline/> | |
+ | |
<group expand="0" string="Group By..."> | |
- <filter string="Commission" context="{'group_by': 'commission'}" icon="terp-dolar"/> | |
- <filter string="Settlement" context="{'group_by': 'settlement'}" icon="terp-dolar"/> | |
+ <filter string="Commission" | |
+ context="{'group_by': 'commission'}" | |
+ icon="terp-dolar" /> | |
+ <filter string="Settlement" | |
+ context="{'group_by': 'settlement'}" | |
+ icon="terp-dolar" /> | |
</group> | |
</search> | |
</field> | |
</record> | |
- | |
<record model="ir.actions.act_window" id="action_saleagent_form"> | |
<field name="name">Sale agents</field> | |
<field name="type">ir.actions.act_window</field> | |
<field name="res_model">sale.agent</field> | |
<field name="view_type">form</field> | |
<field name="view_mode">tree,form</field> | |
- <field name="view_id" ref="view_saleagent_tree"/> | |
- | |
+ <field name="view_id" ref="view_saleagent_tree" /> | |
+ <field name="search_view_id" ref="view_sale_agent_search"/> | |
</record> | |
- | |
<record model="ir.ui.view" id="commission_tree"> | |
<field name="name">commission.tree</field> | |
@@ -112,17 +130,26 @@ | |
</field> | |
</record> | |
+ | |
<record model="ir.ui.view" id="commission_form"> | |
<field name="name">Commissions</field> | |
<field name="model">commission</field> | |
<field name="arch" type="xml"> | |
<form string="Commission"> | |
- <separator string="General info." colspan="4"/> | |
- <field name="name"/> | |
- <field name="type"/> | |
- <group string="Definition of rates" colspan="4"> | |
- <field name="fix_qty" attrs="{'invisible':[('type','!=','fijo')]}"/> | |
- <field name="sections" widget="one2many_list" colspan="4" nolabel="1" attrs="{'invisible':[('type','!=','tramos')]}"> | |
+ <separator string="General information" colspan="4"/> | |
+ <group> | |
+ <field name="name"/> | |
+ <field name="type"/> | |
+ </group> | |
+ | |
+ <group string="Rates definition" colspan="4"> | |
+ <field name="fix_qty" | |
+ attrs="{'invisible':[('type','!=','fijo')]}" /> | |
+ <field name="sections" | |
+ widget="one2many_list" | |
+ colspan="4" | |
+ nolabel="1" | |
+ attrs="{'invisible':[('type','!=','tramos')]}"> | |
<tree string="sections" editable="top"> | |
<field name="commission_from"/> | |
<field name="commission_until"/> | |
@@ -130,25 +157,45 @@ | |
</tree> | |
</field> | |
</group> | |
- | |
+ | |
</form> | |
</field> | |
</record> | |
- <record model="ir.actions.act_window" id="action_commission_form"> | |
+ <record model="ir.actions.act_window" | |
+ id="action_commission_view"> | |
<field name="name">Commission Types</field> | |
<field name="type">ir.actions.act_window</field> | |
<field name="res_model">commission</field> | |
<field name="view_type">form</field> | |
<field name="view_mode">tree,form</field> | |
<field name="view_id" ref="commission_tree"/> | |
- | |
</record> | |
- <menuitem name="Commissions" id="menu_sale_commissions" parent="base.menu_base_partner"/> | |
- <menuitem name="Sale agents" id="menu_sale_commissions_agent" parent="menu_sale_commissions" action="action_saleagent_form" sequence="10"/> | |
- <menuitem name="Commissions" id="menu_sale_commissions_conf" parent="base.menu_base_config"/> | |
- <menuitem name="Commission Types" id="menu_sale_commissions_types" parent="menu_sale_commissions_conf" action="action_commission_form"/> | |
+ | |
+ | |
+ <menuitem name="Commissions" | |
+ id="menu_sale_commissions" | |
+ parent="base.menu_base_partner" | |
+ /> | |
+ | |
+ <menuitem name="Sale agents" | |
+ id="menu_sale_commissions_agent" | |
+ parent="menu_sale_commissions" | |
+ action="action_saleagent_form" | |
+ sequence="10" | |
+ /> | |
+ | |
+ <menuitem name="Commissions" | |
+ id="menu_sale_commissions_conf" | |
+ parent="base.menu_base_config" | |
+ /> | |
+ | |
+ <menuitem name="Commission Types" | |
+ id="menu_sale_commissions_types" | |
+ parent="menu_sale_commissions_conf" | |
+ action="action_commission_view" | |
+ /> | |
</data> | |
</openerp> | |
diff --git a/sale_commission/sale_order.py b/sale_commission/sale_order.py | |
index 9956a95..bb6bb92 100644 | |
--- a/sale_commission/sale_order.py | |
+++ b/sale_commission/sale_order.py | |
@@ -2,7 +2,8 @@ | |
############################################################################## | |
# | |
# OpenERP, Open Source Management Solution | |
-# Copyright (C) 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>). All Rights Reserved | |
+# Copyright (C) 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>). | |
+# All Rights Reserved | |
# $Id$ | |
# | |
# This program is free software: you can redistribute it and/or modify | |
@@ -19,115 +20,147 @@ | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# | |
############################################################################## | |
+from openerp import models, fields, api, _ | |
-"""Modificamos las ventas para incluir el comportamiento de comisiones""" | |
-from osv import fields, orm | |
-from tools.translate import _ | |
- | |
- | |
-class sale_order_agent(orm.Model): | |
+class sale_order_agent(models.Model): | |
_name = "sale.order.agent" | |
- | |
- def name_get(self, cr, uid, ids, context=None): | |
- """devuelve como nombre del agente del partner el nombre del agente""" | |
- if context is None: | |
- context = {} | |
- return [(obj.id, obj.agent_id.name) for obj in self.browse(cr, uid, ids, context=context)] | |
- | |
- _columns = { | |
- 'sale_id': fields.many2one('sale.order', 'Sale order', required=False, ondelete='cascade', help=''), | |
- 'agent_id': fields.many2one('sale.agent', 'Agent', required=True, ondelete='cascade', help=''), | |
- 'commission_id': fields.many2one('commission', 'Applied commission', required=True, ondelete='cascade', | |
- help=''), | |
- } | |
- | |
- def onchange_agent_id(self, cr, uid, ids, agent_id, context=None): | |
- """al cambiar el agente cargamos sus comisión""" | |
- if context is None: | |
- context = {} | |
- result = {} | |
- v = {} | |
- if agent_id: | |
- agent = self.pool.get('sale.agent').browse(cr, uid, agent_id, context=context) | |
- v['commission_id'] = agent.commission.id | |
- result['value'] = v | |
- return result | |
- | |
- def onchange_commission_id(self, cr, uid, ids, agent_id=False, commission_id=False, context=None): | |
- """al cambiar la comisión comprobamos la selección""" | |
- if context is None: | |
- context = {} | |
- result = {} | |
- if commission_id: | |
- partner_commission = self.pool.get('commission').browse(cr, uid, commission_id, context=context) | |
- if partner_commission.sections and agent_id: | |
- agent = self.pool.get('sale.agent').browse(cr, uid, agent_id, context=context) | |
- if agent.commission.id != partner_commission.id: | |
- result['warning'] = { | |
- 'title': _('Fee installments!'), | |
- 'message': _('A commission has been assigned by sections that does not ' | |
- 'match that defined for the agent by default, so that these ' | |
- 'sections shall apply only on this bill.') | |
+ _rec_name = "agent_name" | |
+ | |
+ sale_id = fields.Many2one( | |
+ "sale.order", | |
+ string="Sale order", | |
+ required=False, | |
+ ondelete="cascade" | |
+ ) | |
+ | |
+ commission_id = fields.Many2one( | |
+ "commission", | |
+ string="Commission", | |
+ required=False, | |
+ ondelete="cascade" | |
+ ) | |
+ | |
+ agent_id = fields.Many2one( | |
+ "sale.agent", | |
+ string="Agent", | |
+ required=True, | |
+ ondelete="cascade" | |
+ ) | |
+ | |
+ agent_name = fields.Char( | |
+ string="Agent name", | |
+ related="agent_id.name" | |
+ ) | |
+ | |
+ @api.onchange("agent_id") | |
+ def do_set_default_commission(self): | |
+ """Set default commission when sale agent has changed""" | |
+ self.commission_id = self.agent_id.commission | |
+ | |
+ @api.onchange("commission_id") | |
+ def do_check_commission(self): | |
+ """Check selected commission and raise a warning | |
+ when selected commission is not the default provided for sale agent | |
+ and default partner commission have sections | |
+ """ | |
+ | |
+ commission = self.commission_id | |
+ if commission.id: | |
+ agent_commission = self.agent_id.commission | |
+ if self.agent_id and commission.sections: | |
+ if commission.id != agent_commission.id: | |
+ return { | |
+ "warning": { | |
+ "title": _('Fee installments!'), | |
+ "message": _( | |
+ "Selected commission has been assigned " | |
+ "by sections and it does not match " | |
+ "the one defined to the selected agent." | |
+ "These sections shall apply only on this bill." | |
+ ) | |
+ } | |
} | |
- return result | |
-class sale_order(orm.Model): | |
- """Modificamos las ventas para incluir el comportamiento de comisiones""" | |
+class sale_order(models.Model): | |
+ """Include commission behavior in sale order model""" | |
_inherit = "sale.order" | |
- _columns = { | |
- 'sale_agent_ids': fields.one2many('sale.order.agent', 'sale_id', 'Agents', | |
- states={'draft': [('readonly', False)]}) | |
- } | |
- | |
- def create(self, cr, uid, values, context=None): | |
- if context is None: | |
- context = {} | |
- agent_pool = self.pool.get('sale.order.agent') | |
- res = super(sale_order, self).create(cr, uid, values, context=context) | |
- if 'sale_agent_ids' in values: | |
- for sale_order_agent in values['sale_agent_ids']: | |
- agent_pool.write(cr, uid, sale_order_agent[1], {'sale_id': res}) | |
- return res | |
- def write(self, cr, uid, ids, values, context=None): | |
- if context is None: | |
- context = {} | |
- agent_pool = self.pool.get('sale.order.agent') | |
- if 'sale_agent_ids' in values: | |
- for sale_order_agent in values['sale_agent_ids']: | |
- for id in ids: | |
- if sale_order_agent[2]: | |
- sale_order_agent[2]['sale_id'] = id | |
- else: | |
- agent_pool.unlink(cr, uid, sale_order_agent[1], context=context) | |
- return super(sale_order, self).write(cr, uid, ids, values, context=context) | |
+ sale_agent_ids = fields.One2many( | |
+ "sale.order.agent", | |
+ "sale_id", | |
+ string="Agents", | |
+ states={"draft": [("readonly", False)]} | |
+ ) | |
+ | |
+ # XXX: It doesn't work with Odoo v8.0 and I think it is not necessary | |
+ # def create(self, cr, uid, values, context=None): | |
+ # """Add sale order reference on sale.order.agent | |
+ # """ | |
+ # if context is None: | |
+ # context = {} | |
+ # agent_pool = self.pool.get('sale.order.agent') | |
+ # res = super(sale_order, self).create( | |
+ # cr, uid, values, context=context) | |
+ # if 'sale_agent_ids' in values: | |
+ # for sale_order_agent in values['sale_agent_ids']: | |
+ # agent_pool.write( | |
+ # cr, uid, sale_order_agent[1], {'sale_id': res}) | |
+ # return res | |
+ | |
+ # XXX: It doesn't work with Odoo v8.0 and I think it is not necessary | |
+ # def write(self, cr, uid, ids, values, context=None): | |
+ # """Rebuild sale.order reference on sale.order.agent | |
+ # """ | |
+ # if context is None: | |
+ # context = {} | |
+ # agent_pool = self.pool.get('sale.order.agent') | |
+ # if 'sale_agent_ids' in values: | |
+ # for sale_order_agent in values['sale_agent_ids']: | |
+ # for id in ids: | |
+ # if sale_order_agent[2]: | |
+ # sale_order_agent[2]['sale_id'] = id | |
+ # else: | |
+ # agent_pool.unlink( | |
+ # cr, uid, sale_order_agent[1], context=context) | |
+ # return super(sale_order, self).write( | |
+ # cr, uid, ids, values, context=context) | |
def onchange_partner_id(self, cr, uid, ids, part, context=None): | |
- """heredamos el evento de cambio del campo partner_id para actualizar el campo agent_id""" | |
+ """Agent id field will be changed according to new partner | |
+ """ | |
if context is None: | |
context = {} | |
sale_agent_ids = [] | |
- res = super(sale_order, self).onchange_partner_id(cr, uid, ids, part, context=context) | |
+ res = super(sale_order, self).onchange_partner_id( | |
+ cr, uid, ids, part, context=context | |
+ ) | |
if res.get('value', False) and part: | |
sale_order_agent = self.pool.get('sale.order.agent') | |
if ids: | |
- sale_order_agent.unlink(cr, uid, sale_order_agent.search(cr, uid, [('sale_id', '=', ids)], | |
- context=context)) | |
- partner = self.pool.get('res.partner').browse(cr, uid, part, context=context) | |
+ agent_id = sale_order_agent.search( | |
+ cr, uid, | |
+ [('sale_id', '=', ids)], | |
+ context=context | |
+ ) | |
+ sale_order_agent.unlink(cr, uid, agent_id, context=context) | |
+ partner_obj = self.pool.get('res.partner') | |
+ partner = partner_obj.browse(cr, uid, part, context=context) | |
for partner_agent in partner.commission_ids: | |
vals = { | |
'agent_id': partner_agent.agent_id.id, | |
'commission_id': partner_agent.commission_id.id, | |
- #'sale_id':ids | |
+ # 'sale_id':ids | |
} | |
# FIXME: What is going on in this block? | |
if ids: | |
for id in ids: | |
vals['sale_id'] = id | |
- sale_agent_id = sale_order_agent.create(cr, uid, vals, context=context) | |
+ sale_agent_id = sale_order_agent.create( | |
+ cr, uid, vals, context=context | |
+ ) | |
sale_agent_ids.append(int(sale_agent_id)) | |
res['value']['sale_agent_ids'] = sale_agent_ids | |
return res | |
@@ -137,17 +170,22 @@ class sale_order(orm.Model): | |
if context is None: | |
context = {} | |
picking_pool = self.pool.get('stock.picking') | |
- res = super(sale_order, self).action_ship_create(cr, uid, ids, context=context) | |
+ res = super(sale_order, self).action_ship_create( | |
+ cr, uid, ids, context=context | |
+ ) | |
for order in self.browse(cr, uid, ids, context=context): | |
pickings = [x.id for x in order.picking_ids] | |
agents = [x.agent_id.id for x in order.sale_agent_ids] | |
if pickings and agents: | |
- picking_pool.write(cr, uid, pickings, {'agent_ids': [[6, 0, agents]], }, context=context) | |
+ vals = {'agent_ids': [[6, 0, agents]], } | |
+ picking_pool.write(cr, uid, pickings, vals, context=context) | |
return res | |
-class sale_order_line(orm.Model): | |
- """Modificamos las lineas ventas para incluir las comisiones en las facturas creadas desde ventas""" | |
+class sale_order_line(models.Model): | |
+ """It includes the commission in each invoice line | |
+ when an invoice is created | |
+ """ | |
_inherit = "sale.order.line" | |
@@ -156,18 +194,25 @@ class sale_order_line(orm.Model): | |
context = {} | |
invoice_line_pool = self.pool.get('account.invoice.line') | |
invoice_line_agent_pool = self.pool.get('invoice.line.agent') | |
- res = super(sale_order_line, self).invoice_line_create(cr, uid, ids, context) | |
+ res = super(sale_order_line, self).invoice_line_create( | |
+ cr, uid, ids, context | |
+ ) | |
so_ref = self.browse(cr, uid, ids)[0].order_id | |
for so_agent_id in so_ref.sale_agent_ids: | |
inv_lines = invoice_line_pool.browse(cr, uid, res, context=context) | |
for inv_line in inv_lines: | |
- if inv_line.product_id and inv_line.product_id.commission_exent is not True: | |
+ exent = inv_line.product_id.commission_exent | |
+ if inv_line.product_id and exent is not True: | |
vals = { | |
'invoice_line_id': inv_line.id, | |
'agent_id': so_agent_id.agent_id.id, | |
'commission_id': so_agent_id.commission_id.id, | |
'settled': False | |
} | |
- line_agent_id = invoice_line_agent_pool.create(cr, uid, vals, context=context) | |
- invoice_line_agent_pool.calculate_commission(cr, uid, [line_agent_id], context=context) | |
+ line_agent_id = invoice_line_agent_pool.create( | |
+ cr, uid, vals, context=context | |
+ ) | |
+ invoice_line_agent_pool.calculate_commission( | |
+ cr, uid, [line_agent_id], context=context | |
+ ) | |
return res | |
diff --git a/sale_commission/sale_order_view.xml b/sale_commission/sale_order_view.xml | |
index e54abcf..1e2cec9 100644 | |
--- a/sale_commission/sale_order_view.xml | |
+++ b/sale_commission/sale_order_view.xml | |
@@ -21,39 +21,41 @@ | |
<field name="inherit_id" ref="sale.view_order_form"/> | |
<field name="arch" type="xml"> | |
<field name="user_id" position="after"> | |
- <field name="sale_agent_ids" string="Agents/Consultancy"> | |
- <tree string="Agents and Commissions" editable="top"> | |
- <field name="agent_id" on_change="onchange_agent_id(agent_id)"/> | |
- <field name="commission_id" on_change="onchange_commission_id(agent_id,commission_id)"/> | |
+ <field name="sale_agent_ids" | |
+ string="Agents/Consultancy"> | |
+ <tree string="Agents and Commissions" | |
+ editable="top"> | |
+ <field name="agent_id" /> | |
+ <field name="commission_id" /> | |
</tree> | |
- </field> | |
+ </field> | |
</field> | |
</field> | |
</record> | |
- <record model="ir.ui.view" id="view_sale_agent_comision_tree"> | |
- <field name="name">sale.agent.comision.tree</field> | |
+ <record model="ir.ui.view" id="view_sale_agent_commission_tree"> | |
+ <field name="name">sale.agent.commission.tree</field> | |
<field name="model">sale.order.agent</field> | |
<field name="arch" type="xml"> | |
<tree string="Agents"> | |
<field name="sale_id"/> | |
- <field name="agent_id" on_change="onchange_agent_id(agent_id)"/> | |
- <field name="commission_id" on_change="onchange_commission_id(agent_id,commission_id)"/> | |
+ <field name="agent_id" /> | |
+ <field name="commission_id" /> | |
</tree> | |
</field> | |
</record> | |
- <record model="ir.ui.view" id="sale_order_agent_comision_form"> | |
- <field name="name">sale.order.agent.comision.form.</field> | |
+ <record model="ir.ui.view" id="sale_order_agent_commission_form"> | |
+ <field name="name">sale.order.agent.commission.form</field> | |
<field name="model">sale.order.agent</field> | |
<field name="arch" type="xml"> | |
<form string="Agents"> | |
- <field name="agent_id" on_change="onchange_agent_id(agent_id)"/> | |
- <field name="commission_id" on_change="onchange_commission_id(agent_id,commission_id)"/> | |
+ <field name="agent_id" /> | |
+ <field name="commission_id" /> | |
</form> | |
</field> | |
</record> | |
</data> | |
-</openerp> | |
\ No newline at end of file | |
+</openerp> | |
diff --git a/sale_commission/settled.py b/sale_commission/settled.py | |
index 01b166e..b5c79ae 100644 | |
--- a/sale_commission/settled.py | |
+++ b/sale_commission/settled.py | |
@@ -2,7 +2,8 @@ | |
############################################################################## | |
# | |
# OpenERP, Open Source Management Solution | |
-# Copyright (C) 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>). All Rights Reserved | |
+# Copyright (C) 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>). | |
+# All Rights Reserved | |
# $Id$ | |
# | |
# This program is free software: you can redistribute it and/or modify | |
@@ -19,128 +20,78 @@ | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# | |
############################################################################## | |
- | |
"""Objetos sobre las liquidación""" | |
-from osv import fields, orm, osv | |
-from tools.translate import _ | |
-import time | |
-import tools | |
+from openerp import models, fields, _ | |
+from openerp import tools | |
+from openerp import exceptions | |
-class settled_wizard (orm.TransientModel): | |
- """settled.wizard""" | |
+class settlement(models.Model): | |
+ """Settlement model""" | |
- _name = 'settled.wizard' | |
- _columns = { | |
- 'date_from': fields.date('From', required=True), | |
- 'date_to': fields.date('To', required=True), | |
- } | |
- _defaults = { | |
- } | |
+ _name = "settlement" | |
- def settlement_exec(self, cr, uid, ids, context=None): | |
- """se ejecuta correctamente desde dos.""" | |
- if context is None: | |
- context = {} | |
- pool_liq = self.pool.get('settlement') | |
- for o in self.browse(cr, uid, ids, context=context): | |
- vals = { | |
- 'name': o.date_from + " // " + o.date_to, | |
- 'date_from': o.date_from, | |
- 'date_to': o.date_to | |
- } | |
- liq_id = pool_liq.create(cr, uid, vals, context=context) | |
- pool_liq.calcula(cr, uid, liq_id, context['active_ids'], o.date_from, o.date_to, context=context) | |
+ name = fields.Char( | |
+ string="Settlement period", | |
+ required=True, | |
+ readonly=True | |
+ ) | |
- return { | |
- 'type': 'ir.actions.act_window_close', | |
- } | |
+ total = fields.Float(string="Total", readonly=True) | |
- def action_cancel(self, cr, uid, ids, connect=None, context=None): | |
- """Cancel Liquidation""" | |
- return { | |
- 'type': 'ir.actions.act_window_close', | |
- } | |
+ date_from = fields.Date(string="From") | |
+ date_to = fields.Date(string="To") | |
-class recalculate_commision_wizard (orm.TransientModel): | |
- """settled.wizard""" | |
+ settlement_agent_id = fields.One2many( | |
+ "settlement.agent", | |
+ "settlement_id", | |
+ string="Settlement agents", | |
+ readonly=True) | |
- _name = 'recalculate.commission.wizard' | |
- _columns = { | |
- 'date_from': fields.date('From', required=True), | |
- 'date_to': fields.date('To', required=True), | |
+ date = fields.Datetime( | |
+ string="Created Date", | |
+ required=True, | |
+ default=fields.Datetime.now() | |
+ ) | |
- } | |
- _defaults = { | |
- } | |
+ # TODO: Workflow is necessary to manage 'cancel' state/transition | |
+ state = fields.Selection( | |
+ [ | |
+ ("invoiced", "Invoiced"), | |
+ ("settled", "Settled"), | |
+ ("cancel", "Cancel") | |
+ ], | |
+ string="State", | |
+ readonly=True, | |
+ default="settled" | |
+ ) | |
- def recalculate_exec(self, cr, uid, ids, context=None): | |
- """se ejecuta correctamente desde dos.""" | |
- if context is None: | |
- context = {} | |
- user = self.pool.get('res.users').browse(cr, uid, uid, context=context) | |
- agent_pool = self.pool.get('invoice.line.agent') | |
- for o in self.browse(cr, uid, ids, context=context): | |
- sql = 'SELECT invoice_line_agent.id FROM account_invoice_line ' \ | |
- 'INNER JOIN invoice_line_agent ON invoice_line_agent.invoice_line_id=account_invoice_line.id ' \ | |
- 'INNER JOIN account_invoice ON account_invoice_line.invoice_id = account_invoice.id ' \ | |
- 'WHERE invoice_line_agent.agent_id in (' + ",".join(map(str, context['active_ids'])) + ') ' \ | |
- 'AND invoice_line_agent.settled=False ' \ | |
- 'AND account_invoice.state<>\'draft\' AND account_invoice.type=\'out_invoice\'' \ | |
- 'AND account_invoice.date_invoice >= \'' + o.date_from + '\' ' \ | |
- 'AND account_invoice.date_invoice <= \'' + o.date_to + '\' ' \ | |
- 'AND account_invoice.company_id = ' + str(user.company_id.id) | |
- cr.execute(sql) | |
- res = cr.fetchall() | |
- inv_line_agent_ids = [x[0] for x in res] | |
- agent_pool.calculate_commission(cr, uid, inv_line_agent_ids, context=context) | |
- return { | |
- 'type': 'ir.actions.act_window_close', | |
- } | |
- | |
- def action_cancel(self, cr, uid, ids, connect=None, context=None): | |
- """Cancel Calculation""" | |
- return { | |
- 'type': 'ir.actions.act_window_close', | |
- } | |
- | |
- | |
-class settlement (orm.Model): | |
- """Object Liquidation""" | |
- | |
- _name = 'settlement' | |
- _columns = { | |
- 'name': fields.char('Settlement period', size=64, required=True, readonly=True), | |
- 'total': fields.float('Total', readonly=True), | |
- 'date_from': fields.date('From'), | |
- 'date_to': fields.date('To'), | |
- 'settlement_agent_id': fields.one2many('settlement.agent', 'settlement_id', 'Settlement agents', readonly=True), | |
- 'date': fields.datetime('Created Date', required=True), | |
- 'state': fields.selection([('invoiced', 'Invoiced'), ('settled', 'Settled'), ('cancel', 'Cancel')], 'State', | |
- required=True, readonly=True) | |
- } | |
- _defaults = { | |
- 'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'), | |
- 'state': 'settled' | |
- } | |
- | |
- def action_invoice_create(self, cursor, user, ids, journal_id, product_id, context=None): | |
+ def action_invoice_create(self, cursor, user, ids, | |
+ journal_id, product_id, context=None): | |
if context is None: | |
context = {} | |
agents_pool = self.pool.get('settlement.agent') | |
res = {} | |
for settlement in self.browse(cursor, user, ids, context=context): | |
- settlement_agent_ids = map(lambda x: x.id, settlement.settlement_agent_id) | |
- invoices_agent = agents_pool.action_invoice_create(cursor, user, settlement_agent_ids, journal_id, | |
- product_id, context=context) | |
+ settlement_agent_ids = map( | |
+ lambda x: x.id, settlement.settlement_agent_id | |
+ ) | |
+ invoices_agent = agents_pool.action_invoice_create( | |
+ cursor, user, | |
+ settlement_agent_ids, | |
+ journal_id, | |
+ product_id, | |
+ context=context | |
+ ) | |
res[settlement.id] = invoices_agent.values() | |
return res | |
- def calcula(self, cr, uid, ids, agent_ids, date_from, date_to, context=None): | |
+ def calculate(self, cr, uid, ids, agent_ids, | |
+ date_from, date_to, context=None): | |
"""genera una entrada de liquidación por agente""" | |
- # Busca todas las líneas de liquidación facturadas en un período | |
+ # Busca todas las líneas de liquidación facturadas en un período | |
if context is None: | |
context = {} | |
sale_agent_pool = self.pool.get('sale.agent') | |
@@ -149,10 +100,23 @@ class settlement (orm.Model): | |
total = 0 | |
for agent in agents: | |
# genera una entrada de liquidación por agente | |
- liq_agent_id = settlement_agent_pool.create(cr, uid, {'agent_id': agent.id, 'settlement_id': ids}, | |
- context=context) | |
- settlement_agent_pool.calcula(cr, uid, liq_agent_id, date_from, date_to, context=context) | |
- liq_agent = settlement_agent_pool.browse(cr, uid, liq_agent_id, context=context) | |
+ liq_agent_id = settlement_agent_pool.create( | |
+ cr, uid, | |
+ {'agent_id': agent.id, 'settlement_id': ids}, | |
+ context=context | |
+ ) | |
+ settlement_agent_pool.calculate( | |
+ cr, uid, | |
+ liq_agent_id, | |
+ date_from, | |
+ date_to, | |
+ context=context | |
+ ) | |
+ liq_agent = settlement_agent_pool.browse( | |
+ cr, uid, | |
+ liq_agent_id, | |
+ context=context | |
+ ) | |
total = total + liq_agent.total | |
return self.write(cr, uid, ids, {'total': total}, context=context) | |
@@ -164,9 +128,16 @@ class settlement (orm.Model): | |
for settle in self.browse(cr, uid, ids, context=context): | |
for settle_line in settle.settlement_agent_id: | |
for line in settle_line.lines: | |
- commission_ids = line.invoice_line_id and [x.id for x in line.invoice_line_id.commission_ids] or [] | |
+ line_id = line.invoice_line_id | |
+ commissions = [x.id for x in line_id.commission_ids] | |
+ commission_ids = line.invoice_line_id and commissions or [] | |
if commission_ids: | |
- agent_pool.write(cr, uid, commission_ids, {'settled': False, 'quantity': 0.0}, context=context) | |
+ agent_pool.write( | |
+ cr, uid, | |
+ commission_ids, | |
+ {'settled': False, 'quantity': 0.0}, | |
+ context=context | |
+ ) | |
return self.write(cr, uid, ids, {'state': 'cancel'}, context=context) | |
def unlink(self, cr, uid, ids, context=None): | |
@@ -175,45 +146,86 @@ class settlement (orm.Model): | |
context = {} | |
for settle in self.browse(cr, uid, ids, context=context): | |
if settle.state != 'cancel': | |
- raise osv.except_osv(_('Error!'), _("You can\'t delete it, if it isn't in cancel state.")) | |
+ raise exceptions.Warning( | |
+ _("You can\'t delete it, if it isn't in cancel state.") | |
+ ) | |
return super(settlement, self).unlink(cr, uid, ids, context=context) | |
-class settlement_agent (orm.Model): | |
+class settlement_agent(models.Model): | |
"""Liquidaciones de Agentes""" | |
_name = 'settlement.agent' | |
- def _invoice_line_hook(self, cursor, user, move_line, invoice_line_id, context=None): | |
+ def _invoice_line_hook(self, cursor, user, | |
+ move_line, invoice_line_id, context=None): | |
'''Call after the creation of the invoice line''' | |
return | |
def _get_address_invoice(self, cr, uid, settlement, context=None): | |
- '''Return {'default: address, 'contact': address, 'invoice': address} for invoice''' | |
+ """Return | |
+ { | |
+ 'default: address, | |
+ 'contact': address, | |
+ 'invoice': address | |
+ } for invoice | |
+ """ | |
if context is None: | |
context = {} | |
partner_obj = self.pool.get('res.partner') | |
partner = settlement.agent_id.partner_id | |
- return partner_obj.address_get(cr, uid, [partner.id], ['default', 'contact', 'invoice'], context=context) | |
+ return partner_obj.address_get( | |
+ cr, uid, | |
+ [partner.id], | |
+ ['default', 'contact', 'invoice'], | |
+ context=context | |
+ ) | |
def _invoice_hook(self, cr, uid, picking, invoice_id, context=None): | |
'''Call after the creation of the invoice''' | |
return | |
- _columns = { | |
- 'agent_id': fields.many2one('sale.agent', 'Agent', required=True, select=1), | |
- 'total_per': fields.float('Total percentages', readonly=True), | |
- 'total_sections': fields.float('Total sections', readonly=True), | |
- 'total': fields.float('Total', readonly=True), | |
- 'lines': fields.one2many('settlement.line', 'settlement_agent_id', 'Lines', readonly=True), | |
- 'invoices': fields.one2many('settled.invoice.agent', 'settlement_agent_id', 'Invoices', readonly=True), | |
- 'settlement_id': fields.many2one('settlement', 'Settlement', required=True, ondelete="cascade") | |
- } | |
+ agent_id = fields.Many2one( | |
+ "sale.agent", | |
+ string="Agent", | |
+ required=True, | |
+ select=1 | |
+ ) | |
+ | |
+ total_per = fields.Float( | |
+ string="Total percentages", | |
+ readonly=True | |
+ ) | |
+ total_sections = fields.Float(string="Total sections", readonly=True) | |
+ | |
+ total = fields.Float(string="Total", readonly=True) | |
+ | |
+ lines = fields.One2many( | |
+ "settlement.line", | |
+ "settlement_agent_id", | |
+ string="Lines", | |
+ readonly=True | |
+ ) | |
+ | |
+ invoices = fields.One2many( | |
+ "settled.invoice.agent", | |
+ "settlement_agent_id", | |
+ string="Invoices", | |
+ readonly=True | |
+ ) | |
+ | |
+ settlement_id = fields.Many2one( | |
+ "settlement", | |
+ string="Settlement", | |
+ required=True, | |
+ ondelete="cascade" | |
+ ) | |
def get_currency_id(self, cr, uid, picking, context=None): | |
return False | |
- def action_invoice_create(self, cr, uid, ids, journal_id, product_id, context=None): | |
+ def action_invoice_create(self, cr, uid, | |
+ ids, journal_id, product_id, context=None): | |
'''Return ids of created invoices for the settlements''' | |
if context is None: | |
context = {} | |
@@ -226,12 +238,17 @@ class settlement_agent (orm.Model): | |
payment_term_id = False | |
partner = settlement.agent_id and settlement.agent_id.partner_id | |
if not partner: | |
- raise osv.except_osv(_('Error, partner fail !'), | |
- _('Agent to settle hasn\'t assigned partner.')) | |
- #El tipo es de facura de proveedor | |
+ raise exceptions.Warning( | |
+ _('Agent to settle hasn\'t assigned partner.') | |
+ ) | |
+ # El tipo es de facura de proveedor | |
account_id = partner.property_account_payable.id | |
- address_default_id, address_contact_id, address_invoice_id = \ | |
- self._get_address_invoice(cr, uid, settlement, context=context).values() | |
+ address_default_id, address_contact_id, address_invoice_id = ( | |
+ self._get_address_invoice( | |
+ cr, uid, settlement, context=context | |
+ ).values() | |
+ ) | |
+ | |
# No se agrupa | |
invoice_vals = { | |
'name': settlement.settlement_id.name, | |
@@ -249,7 +266,9 @@ class settlement_agent (orm.Model): | |
invoice_vals['currency_id'] = cur_id | |
if journal_id: | |
invoice_vals['journal_id'] = journal_id | |
- invoice_id = invoice_obj.create(cr, uid, invoice_vals, context=context) | |
+ invoice_id = invoice_obj.create( | |
+ cr, uid, invoice_vals, context=context | |
+ ) | |
res[settlement.id] = invoice_id | |
# El producto se selecciona en el wizard correspondiente | |
product = product_pool.browse(cr, uid, product_id, context=context) | |
@@ -275,11 +294,13 @@ class settlement_agent (orm.Model): | |
name = invoice.invoice_number | |
price_unit = invoice.settled_amount | |
discount = 0 | |
- #set UoS if it's a sale and the picking doesn't have one | |
+ # set UoS if it's a sale and the picking doesn't have one | |
uos_id = False | |
- account_id = account_fiscal_position_pool.map_account(cr, uid, | |
- partner.property_account_position, account_id, | |
- context=context) | |
+ account_id = account_fiscal_position_pool.map_account( | |
+ cr, uid, | |
+ partner.property_account_position, | |
+ account_id, | |
+ context=context) | |
invoice_line_id = invoice_line_obj.create(cr, uid, { | |
'name': name, | |
'origin': origin, | |
@@ -292,13 +313,19 @@ class settlement_agent (orm.Model): | |
'quantity': 1, | |
'invoice_line_tax_id': [(6, 0, tax_ids)], | |
}, context=context) | |
- self._invoice_line_hook(cr, uid, invoice, invoice_line_id, context=context) | |
- invoice_obj.button_compute(cr, uid, [invoice_id], context=context, | |
- set_total=(type in ('in_invoice', 'in_refund'))) | |
- self._invoice_hook(cr, uid, settlement, invoice_id, context=context) | |
+ self._invoice_line_hook( | |
+ cr, uid, invoice, invoice_line_id, context=context | |
+ ) | |
+ invoice_obj.button_compute( | |
+ cr, uid, [invoice_id], context=context, | |
+ set_total=(type in ('in_invoice', 'in_refund')) | |
+ ) | |
+ self._invoice_hook( | |
+ cr, uid, settlement, invoice_id, context=context | |
+ ) | |
return res | |
- def calcula(self, cr, uid, ids, date_from, date_to, context=None): | |
+ def calculate(self, cr, uid, ids, date_from, date_to, context=None): | |
if context is None: | |
context = {} | |
settlement_line_pool = self.pool.get('settlement.line') | |
@@ -306,28 +333,49 @@ class settlement_agent (orm.Model): | |
set_agent = self.browse(cr, uid, ids, context=context) | |
user = self.pool.get('res.users').browse(cr, uid, uid, context=context) | |
# Recalculamos todas las lineas sujetas a comision | |
- sql = 'SELECT invoice_line_agent.id FROM account_invoice_line ' \ | |
- 'INNER JOIN invoice_line_agent ON invoice_line_agent.invoice_line_id=account_invoice_line.id ' \ | |
- 'INNER JOIN account_invoice ON account_invoice_line.invoice_id = account_invoice.id ' \ | |
- 'WHERE invoice_line_agent.agent_id=' + str(set_agent.agent_id.id) + ' ' \ | |
- 'AND invoice_line_agent.settled=True ' \ | |
- 'AND account_invoice.state<>\'draft\' AND account_invoice.type=\'out_invoice\''\ | |
- 'AND account_invoice.date_invoice >= \'' + date_from + '\' ' \ | |
- 'AND account_invoice.date_invoice <= \'' + date_to + '\' ' \ | |
- 'AND account_invoice.company_id = ' + str(user.company_id.id) | |
+ sql = """ | |
+ SELECT invoice_line_agent.id FROM account_invoice_line | |
+ INNER JOIN invoice_line_agent | |
+ ON invoice_line_agent.invoice_line_id=account_invoice_line.id | |
+ INNER JOIN account_invoice | |
+ ON account_invoice_line.invoice_id = account_invoice.id | |
+ WHERE invoice_line_agent.agent_id={} | |
+ AND invoice_line_agent.settled=True | |
+ AND account_invoice.state<>'draft' | |
+ AND account_invoice.type='out_invoice' | |
+ AND account_invoice.date_invoice >= '{}' | |
+ AND account_invoice.date_invoice <= '' | |
+ AND account_invoice.company_id = {}' | |
+ """.format( | |
+ set_agent.agent_id.id, | |
+ date_from, | |
+ date_to, | |
+ user.company_id.id | |
+ ) | |
cr.execute(sql) | |
res = cr.fetchall() | |
inv_line_agent_ids = [x[0] for x in res] | |
- invoice_line_agent_pool .calculate_commission(cr, uid, inv_line_agent_ids, context=context) | |
- sql = 'SELECT account_invoice_line.id FROM account_invoice_line ' \ | |
- 'INNER JOIN invoice_line_agent ON invoice_line_agent.invoice_line_id=account_invoice_line.id ' \ | |
- 'INNER JOIN account_invoice ON account_invoice_line.invoice_id = account_invoice.id ' \ | |
- 'WHERE invoice_line_agent.agent_id=' + str(set_agent.agent_id.id) + ' ' \ | |
- 'AND invoice_line_agent.settled=False ' \ | |
- 'AND account_invoice.state<>\'draft\' AND account_invoice.type=\'out_invoice\'' \ | |
- 'AND account_invoice.date_invoice >= \'' + date_from + '\' ' \ | |
- 'AND account_invoice.date_invoice <= \'' + date_to + '\' ' \ | |
- 'AND account_invoice.company_id = ' + str(user.company_id.id) | |
+ invoice_line_agent_pool .calculate_commission( | |
+ cr, uid, inv_line_agent_ids, context=context | |
+ ) | |
+ sql = """ | |
+ SELECT account_invoice_line.id FROM account_invoice_line | |
+ INNER JOIN invoice_line_agent | |
+ ON invoice_line_agent.invoice_line_id=account_invoice_line.id | |
+ INNER JOIN account_invoice | |
+ ON account_invoice_line.invoice_id = account_invoice.id | |
+ WHERE invoice_line_agent.agent_id={} | |
+ AND invoice_line_agent.settled=False | |
+ AND account_invoice.state<>'draft' | |
+ AND account_invoice.type='out_invoice' | |
+ AND account_invoice.date_invoice >= '{}' | |
+ AND account_invoice.date_invoice <= '{}' | |
+ AND account_invoice.company_id = {}""".format( | |
+ set_agent.agent_id.id, | |
+ date_from, | |
+ date_to, | |
+ user.company_id.id | |
+ ) | |
cr.execute(sql) | |
res = cr.fetchall() | |
inv_line_ids = [x[0] for x in res] | |
@@ -335,77 +383,144 @@ class settlement_agent (orm.Model): | |
total_sections = 0 | |
sections = {} | |
for inv_line_id in inv_line_ids: | |
- linea_id = settlement_line_pool.create(cr, uid, | |
- {'invoice_line_id': inv_line_id, 'settlement_agent_id': ids}, | |
- context=context) | |
- settlement_line_pool.calcula(cr, uid, linea_id, context=context) | |
- line = settlement_line_pool.browse(cr, uid, linea_id, context=context) | |
- # Marca la comision en la factura como liquidada y establece la cantidad | |
- # Si es por tramos la cantidad será cero, pero se reflejará sobre el tramo del Agente | |
+ linea_id = settlement_line_pool.create( | |
+ cr, uid, | |
+ {'invoice_line_id': inv_line_id, 'settlement_agent_id': ids}, | |
+ context=context | |
+ ) | |
+ settlement_line_pool.calculate(cr, uid, linea_id, context=context) | |
+ line = settlement_line_pool.browse( | |
+ cr, uid, linea_id, context=context | |
+ ) | |
+ # Marca la comision en la factura como liquidada | |
+ # y establece la cantidad | |
+ # Si es por tramos la cantidad será cero, | |
+ # pero se reflejará sobre el tramo del Agente | |
if line.commission_id.type == "fijo": | |
total_per = total_per + line.commission | |
- inv_ag_ids = invoice_line_agent_pool.search(cr, uid, [('invoice_line_id', '=', inv_line_id), | |
- ('agent_id', '=', set_agent.agent_id.id)], | |
- context=context) | |
- invoice_line_agent_pool.write(cr, uid, inv_ag_ids, {'settled': True, 'quantity': line.commission}, | |
- context=context) | |
- if line.commission_id.type == "tramos" and not line.invoice_line_id.product_id.commission_exent: | |
- # Hacemos un agregado de la base de cálculo agrupándolo por las distintas comisiones en tramos que | |
+ inv_ag_ids = invoice_line_agent_pool.search( | |
+ cr, uid, | |
+ [('invoice_line_id', '=', inv_line_id), | |
+ ('agent_id', '=', set_agent.agent_id.id)], | |
+ context=context | |
+ ) | |
+ | |
+ invoice_line_agent_pool.write( | |
+ cr, uid, | |
+ inv_ag_ids, | |
+ {'settled': True, 'quantity': line.commission}, | |
+ context=context | |
+ ) | |
+ product_id = line.invoice_line_id.product_id | |
+ is_commission_exent = product_id.commission_exent | |
+ if line.commission_id.type == "tramos" and not is_commission_exent: | |
+ # Hacemos un agregado de la base de cálculo agrupándolo | |
+ # por las distintas comisiones en tramos que | |
# tenga el agente asignadas | |
if line.commission_id.id in sections: | |
- sections[line.commission_id.id]['base'] = (sections[line.commission_id.id]['base'] + | |
- line.invoice_line_id.price_subtotal) | |
- # Añade la línea de la que se añade esta base para el cálculo por tramos | |
+ sections[line.commission_id.id]['base'] = ( | |
+ sections[line.commission_id.id]['base'] + | |
+ line.invoice_line_id.price_subtotal | |
+ ) | |
+ # Añade la línea de la que se añade esta base | |
+ # para el cálculo por tramos | |
sections[line.commission_id.id]['lines'].append(line) | |
else: | |
- sections[line.commission_id.id] = {'type': line.commission_id, | |
- 'base': line.invoice_line_id.price_subtotal, | |
- 'lines': [line]} | |
- #Tramos para cada tipo de comisión creados | |
+ sections[line.commission_id.id] = { | |
+ 'type': line.commission_id, | |
+ 'base': line.invoice_line_id.price_subtotal, | |
+ 'lines': [line] | |
+ } | |
+ # Tramos para cada tipo de comisión creados | |
for tramo in sections: | |
- #Cálculo de la comisión para cada tramo | |
- sections[tramo].update({'commission': sections[tramo]['type'].calcula_tramos(sections[tramo]['base'])}) | |
+ # Cálculo de la comisión para cada tramo | |
+ tramo = sections[tramo] | |
+ sections[tramo].update( | |
+ { | |
+ 'commission': tramo['type'].calcula_tramos(tramo['base']) | |
+ } | |
+ ) | |
total_sections = total_sections + sections[tramo]['commission'] | |
# reparto de la comisión para cada linea | |
for linea_tramo in sections[tramo]['lines']: | |
+ subtotal = linea_tramo.invoice_line_id.price_subtotal | |
com_por_linea = (sections[tramo]['commission'] * | |
- (linea_tramo.invoice_line_id.price_subtotal / sections[tramo]['base'])) | |
+ (subtotal / sections[tramo]['base'])) | |
linea_tramo.write({'commission': com_por_linea}) | |
inv_ag_ids = invoice_line_agent_pool.search(cr, uid, [ | |
('invoice_line_id', '=', linea_tramo.invoice_line_id.id), | |
('agent_id', '=', set_agent.agent_id.id) | |
], context=context) | |
- invoice_line_agent_pool.write(cr, uid, inv_ag_ids, {'settled': True, 'quantity': com_por_linea}, | |
- context=context) | |
+ invoice_line_agent_pool.write( | |
+ cr, uid, inv_ag_ids, | |
+ {'settled': True, 'quantity': com_por_linea}, | |
+ context=context | |
+ ) | |
total = total_per + total_sections | |
- self.write(cr, uid, ids, {'total_per': total_per, 'total_sections': total_sections, 'total': total}, | |
- context=context) | |
- | |
- | |
-class settlement_line (orm.Model): | |
+ self.write( | |
+ cr, uid, ids, | |
+ { | |
+ 'total_per': total_per, | |
+ 'total_sections': total_sections, | |
+ 'total': total | |
+ }, | |
+ context=context | |
+ ) | |
+ | |
+ | |
+class settlement_line(models.Model): | |
"""Línea de las liquidaciones de los agentes | |
Una línea por línea de factura | |
""" | |
- _name = 'settlement.line' | |
- _columns = { | |
- 'invoice_id': fields.related('invoice_line_id', 'invoice_id', type='many2one', relation='account.invoice', | |
- string='Invoice'), | |
- 'invoice_date': fields.related('invoice_id', 'date_invoice', type='date', readonly=True, string='Invoice Date'), | |
- 'settlement_agent_id': fields.many2one('settlement.agent', 'Settlement agent', required=True, select=1, | |
- ondelete="cascade"), | |
- 'invoice_line_id': fields.many2one('account.invoice.line', 'Settled invoice line', required=True), | |
- 'amount': fields.float('Invoice line amount', readonly=True), | |
- 'currency_id': fields.many2one('res.currency', 'Currency', readonly=True), | |
- 'commission_id': fields.many2one('commission', 'Commission', readonly=True), | |
- 'commission': fields.float('Quantity', readonly=True), | |
- } | |
- | |
- _defaults = { | |
- 'currency_id': (lambda self, cr, uid, context: | |
- self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id.id) | |
- } | |
- | |
- def calcula(self, cr, uid, ids, context=None): | |
+ _name = "settlement.line" | |
+ | |
+ def _default_currency(self): | |
+ # BBB: I think this is wrong... | |
+ # sale order o invoice could be in a different currency | |
+ company = self.env.user.company_id | |
+ return company.currency_id.id | |
+ | |
+ invoice_id = fields.Many2one( | |
+ "account.invoice", | |
+ string="Invoice", | |
+ related="invoice_line_id.invoice_id" | |
+ ) | |
+ | |
+ invoice_date = fields.Date( | |
+ string="Invoice Date", | |
+ related="invoice_id.date_invoice", | |
+ readonly=True | |
+ ) | |
+ | |
+ settlement_agent_id = fields.Many2one( | |
+ "settlement.agent", | |
+ string="Settlement agent", | |
+ required=True, | |
+ select=1, | |
+ ondelete="cascade" | |
+ ) | |
+ invoice_line_id = fields.Many2one( | |
+ "account.invoice.line", | |
+ string="Settled invoice line", | |
+ required=True | |
+ ) | |
+ | |
+ amount = fields.Float(string="Invoice line amount", readonly=True) | |
+ | |
+ currency_id = fields.Many2one( | |
+ "res.currency", | |
+ string="Currency", | |
+ readonly=True, | |
+ default=_default_currency | |
+ ) | |
+ commission_id = fields.Many2one( | |
+ "commission", | |
+ string="Commission", | |
+ readonly=True | |
+ ) | |
+ commission = fields.Float(string="Quantity", readonly=True) | |
+ | |
+ def calculate(self, cr, uid, ids, context=None): | |
if context is None: | |
context = {} | |
currency_pool = self.pool.get('res.currency') | |
@@ -416,59 +531,120 @@ class settlement_line (orm.Model): | |
for commission in line.invoice_line_id.commission_ids: | |
# selecciona el asignado al agente para el que está liquidando | |
if commission.agent_id.id == line.settlement_agent_id.agent_id.id: | |
- commission_app = commission.commission_id # Obtiene el objeto | |
+ commission_app = commission.commission_id # Obtiene el objeto | |
invoice_line_amount = line.invoice_line_id.price_subtotal | |
if commission_app.type == "fijo": | |
commission_per = commission_app.fix_qty | |
- amount = amount + line.invoice_line_id.price_subtotal * float(commission_per) / 100 | |
+ subtotal = line.invoice_line_id.price_subtotal | |
+ amount = amount + subtotal * float(commission_per) / 100 | |
elif commission_app.type == "tramos": | |
invoice_line_amount = 0 | |
amount = 0 | |
- cc_amount_subtotal = (line.invoice_id.currency_id.id != user.company_id.currency_id.id and | |
- currency_pool.compute(cr, uid, line.invoice_id.currency_id.id, | |
- user.company_id.currency_id.id, invoice_line_amount, | |
- round=False, context=context) or | |
- invoice_line_amount) | |
- cc_commission_amount = (line.invoice_id.currency_id.id != user.company_id.currency_id.id and | |
- currency_pool.compute(cr, uid, line.invoice_id.currency_id.id, | |
- user.company_id.currency_id.id, amount, round=False, | |
- context=context) or | |
- amount) | |
- self.write(cr, uid, ids, {'amount': cc_amount_subtotal, | |
- 'commission_id': commission_app.id, | |
- 'commission': cc_commission_amount, | |
- 'currency_id': user.company_id.currency_id.id}) | |
- | |
- | |
-class settled_invoice_agent(orm.Model): | |
+ invoice_currency_id = line.invoice_id.currency_id.id | |
+ company_currency_id = user.company_id.currency_id.id | |
+ cc_amount_subtotal = ( | |
+ invoice_currency_id != company_currency_id and | |
+ currency_pool.compute( | |
+ cr, uid, invoice_currency_id, | |
+ company_currency_id, | |
+ invoice_line_amount, | |
+ round=False, | |
+ context=context) | |
+ or | |
+ invoice_line_amount | |
+ ) | |
+ cc_commission_amount = ( | |
+ invoice_currency_id != company_currency_id and | |
+ currency_pool.compute( | |
+ cr, uid, invoice_currency_id, | |
+ company_currency_id, | |
+ amount, | |
+ round=False, | |
+ context=context) | |
+ or | |
+ amount | |
+ ) | |
+ self.write( | |
+ cr, uid, ids, | |
+ { | |
+ 'amount': cc_amount_subtotal, | |
+ 'commission_id': commission_app.id, | |
+ 'commission': cc_commission_amount, | |
+ 'currency_id': user.company_id.currency_id.id | |
+ } | |
+ ) | |
+ | |
+ | |
+class settled_invoice_agent(models.Model): | |
_name = "settled.invoice.agent" | |
- _description = "Resumen de facturas liquidadas" | |
+ _description = "Sale Agents' invoices summary" | |
_auto = False | |
- _columns = { | |
- 'agent_id': fields.many2one('sale.agent', 'Agent', readonly=True, select=1), | |
- 'invoice_id': fields.many2one('account.invoice', 'Invoice', readonly=True, select=1), | |
- 'settlement_agent_id': fields.many2one('settlement.agent', 'Agent settl.', readonly=True, select=1, | |
- ondelete="cascade"), | |
- 'invoice_number': fields.related('invoice_id', 'number', type='char', string='Invoice no', readonly=True), | |
- 'invoice_date': fields.related('invoice_id', 'date_invoice', string='Invoice date', type='date', readonly=True, | |
- select=1), | |
- 'invoice_amount': fields.float('Amount assigned in invoice', readonly=True), | |
- 'settled_amount': fields.float('Settled amount', readonly=True), | |
- } | |
+ | |
+ agent_id = fields.Many2one( | |
+ "sale.agent", | |
+ string="Agent", | |
+ readonly=True, | |
+ select=1 | |
+ ) | |
+ | |
+ invoice_id = fields.Many2one( | |
+ "account.invoice", | |
+ string="Invoice", | |
+ readonly=True, | |
+ select=1 | |
+ ) | |
+ | |
+ settlement_agent_id = fields.Many2one( | |
+ "settlement.agent", | |
+ string="Agent settl.", | |
+ readonly=True, | |
+ select=1, | |
+ ondelete="cascade" | |
+ ) | |
+ | |
+ invoice_number = fields.Char( | |
+ string="Invoice no", | |
+ related="invoice_id.number", | |
+ readonly=True | |
+ ) | |
+ | |
+ invoice_date = fields.Date( | |
+ string="Invoice date", | |
+ related="invoice_id.date_invoice", | |
+ readonly=True, | |
+ select=1 | |
+ ) | |
+ | |
+ invoice_amount = fields.Float( | |
+ string="Amount assigned in invoice", | |
+ readonly=True | |
+ ) | |
+ | |
+ settled_amount = fields.Float( | |
+ string="Settled amount", | |
+ readonly=True | |
+ ) | |
def init(self, cr): | |
tools.sql.drop_view_if_exists(cr, "settled_invoice_agent", ) | |
cr.execute(""" | |
create or replace view settled_invoice_agent as ( | |
- SELECT (account_invoice_line.invoice_id*10000+settlement_agent.agent_id) as id, | |
+ SELECT ( | |
+ account_invoice_line.invoice_id*10000+settlement_agent.agent_id | |
+ ) as id, | |
settlement_agent.id as settlement_agent_id, | |
account_invoice_line.invoice_id as invoice_id, | |
settlement_agent.agent_id as agent_id, | |
sum(settlement_line.amount) as invoice_amount, | |
sum(settlement_line.commission) as settled_amount | |
FROM settlement_agent | |
- INNER JOIN settlement_line ON settlement_agent.id = settlement_line.settlement_agent_id | |
- INNER JOIN account_invoice_line ON account_invoice_line.id = settlement_line.invoice_line_id | |
- GROUP BY account_invoice_line.invoice_id, settlement_agent.agent_id, settlement_agent.id | |
+ INNER JOIN settlement_line | |
+ ON settlement_agent.id = settlement_line.settlement_agent_id | |
+ INNER JOIN account_invoice_line | |
+ ON account_invoice_line.id = settlement_line.invoice_line_id | |
+ GROUP BY | |
+ account_invoice_line.invoice_id, | |
+ settlement_agent.agent_id, | |
+ settlement_agent.id | |
)""") | |
diff --git a/sale_commission/settled_view.xml b/sale_commission/settled_view.xml | |
index 555e3fd..2ec49d8 100644 | |
--- a/sale_commission/settled_view.xml | |
+++ b/sale_commission/settled_view.xml | |
@@ -2,83 +2,6 @@ | |
<openerp> | |
<data> | |
- <record id="view_settled_wizard" model="ir.ui.view"> | |
- <field name="name">Select period to settle</field> | |
- <field name="model">settled.wizard</field> | |
- <field name="arch" type="xml"> | |
- <form string="Select period to Settle"> | |
- <field name="date_from" /> | |
- <field name="date_to" /> | |
- <button icon="gtk-cancel" name="action_cancel" type="object" special="cancel" string="Cancel"/> | |
- <button icon="gtk-ok" name="settlement_exec" string="Run Settlement Agents" type="object"/> | |
- </form> | |
- </field> | |
- </record> | |
- | |
- <record id="view_recalculate_commision_wizard" model="ir.ui.view"> | |
- <field name="name">Select period to recalculate</field> | |
- <field name="model">recalculate.commission.wizard</field> | |
- <field name="arch" type="xml"> | |
- <form string="Select period to recalculate commissions"> | |
- <field name="date_from" /> | |
- <field name="date_to" /> | |
- <group col="4" colspan="4"> | |
- <button icon="gtk-cancel" name="action_cancel" type="object" special="cancel" string="Cancel"/> | |
- <button icon="gtk-ok" name="recalculate_exec" string="Recalculate agents commissions" type="object"/> | |
- </group> | |
- </form> | |
- </field> | |
- </record> | |
- | |
- | |
- <!--record id="action_settlement_wizard" model="ir.actions.act_window"> | |
- <field name="name">Run Settlement Agents</field> | |
- <field name="type">ir.actions.act_window</field> | |
- <field name="res_model">settled.wizard</field> | |
- <field name="view_type">form</field> | |
- <field name="view_mode">form</field> | |
- <field name="target">new</field> | |
- </record--> | |
- | |
- <act_window name="Perform agents settlements" | |
- res_model="settled.wizard" | |
- src_model="sale.agent" | |
- multi="True" | |
- view_mode="form" | |
- view_type="form" | |
- target="new" | |
- id="action_agents_settlement"/> | |
- | |
- <record id="action_wizard_settled" model="ir.values"> | |
- <field name="object" eval="1" /> | |
- <field name="name">Perform agents settlements</field> | |
- <field name="key2">client_action_multi</field> | |
- <field name="value" eval="'ir.actions.act_window,' + str(ref('action_agents_settlement'))"/> | |
- <field name="key">action</field> | |
- <field name="model">sale.agent</field> | |
- </record> | |
- | |
- | |
- <act_window name="Recalculate agents commissions" | |
- res_model="recalculate.commission.wizard" | |
- src_model="sale.agent" | |
- multi="True" | |
- view_mode="form" | |
- view_type="form" | |
- target="new" | |
- id="action_recalculate_commission"/> | |
- | |
- <record id="action_wizard_recalculate_commission" model="ir.values"> | |
- <field name="object" eval="1" /> | |
- <field name="name">Recalculate agents commissions</field> | |
- <field name="key2">client_action_multi</field> | |
- <field name="value" eval="'ir.actions.act_window,' + str(ref('action_recalculate_commission'))"/> | |
- <field name="key">action</field> | |
- <field name="model">sale.agent</field> | |
- </record> | |
- | |
- | |
- | |
<record model="ir.ui.view" id="view_settlement_line_tree"> | |
<field name="name">Settlement Lines</field> | |
<field name="model">settlement.line</field> | |
@@ -100,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> | |
@@ -145,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> | |
@@ -184,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> | |
@@ -196,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> | |
@@ -213,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> | |
@@ -267,28 +211,50 @@ | |
<field name="model">settlement</field> | |
<field name="arch" type="xml"> | |
<form string="Settlements"> | |
- <field name="name"/> | |
- <field name="total"/> | |
- <field name="date_from"/> | |
- <field name="date_to"/> | |
- <newline/> | |
- <label colspan="4" string="Agents summary"/> | |
- <field name="settlement_agent_id" colspan="4" 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> | |
- <field name="state"/> | |
- <button name="%(action_settled_invoice)d" string="Create Invoices" attrs="{'invisible': [('state','!=','settled')]}" type="action" icon="terp-gtk-go-back-rtl" /> | |
- <button string="Cancel" name="action_cancel" type="object" states="settled"/> | |
+ <header> | |
+ <button name="%(action_settled_invoice)d" | |
+ string="Create Invoices" | |
+ attrs="{'invisible': [('state','!=','settled')]}" | |
+ type="action" | |
+ icon="terp-gtk-go-back-rtl" /> | |
+ | |
+ <button string="Cancel" | |
+ name="action_cancel" | |
+ type="object" | |
+ states="settled" /> | |
+ | |
+ <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> | |
@@ -296,10 +262,14 @@ | |
<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" id="menu_settlement" parent="menu_sale_commissions" action="act_settlement" sequence="20"/> | |
+ <menuitem name="Settlements" | |
+ id="menu_settlement" | |
+ parent="menu_sale_commissions" | |
+ action="act_settlement" | |
+ sequence="20" /> | |
<record model="ir.actions.act_window" id="act_settlement_agent"> | |
@@ -313,8 +283,19 @@ | |
</record> | |
- <menuitem name="Reports" id="menu_commisions_report" parent="menu_sale_commissions" sequence="30"/> | |
- <menuitem name="Agents setlements summary" id="menu_agent_settlement" parent="menu_commisions_report" action="act_settlement_agent"/> | |
+ <menuitem name="Reports" | |
+ id="menu_commisions_report" | |
+ parent="menu_sale_commissions" | |
+ sequence="30" | |
+ /> | |
+ | |
+ | |
+ <menuitem name="Agents setlements summary" | |
+ id="menu_agent_settlement" | |
+ parent="menu_commisions_report" | |
+ action="act_settlement_agent" | |
+ /> | |
+ | |
<record model="ir.actions.act_window" id="act_settled_invoice_agent"> | |
<field name="name">Settled invoices summary</field> | |
@@ -323,11 +304,14 @@ | |
<field name="view_type">form</field> | |
<field name="view_mode">tree,form</field> | |
<field name="view_id" ref="view_settled_invoice_agent_tree"/> | |
- | |
</record> | |
- <menuitem name="Settled invoices summary" id="menu_agent_invoice_settled" parent="menu_commisions_report" action="act_settled_invoice_agent"/> | |
- </data> | |
+ <menuitem name="Settled invoices summary" | |
+ id="menu_agent_invoice_settled" | |
+ parent="menu_commisions_report" | |
+ action="act_settled_invoice_agent" | |
+ /> | |
+ </data> | |
</openerp> | |
diff --git a/sale_commission/settlement_wizard.xml b/sale_commission/settlement_wizard.xml | |
deleted file mode 100644 | |
index a60da1c..0000000 | |
--- a/sale_commission/settlement_wizard.xml | |
+++ /dev/null | |
@@ -1,15 +0,0 @@ | |
-<?xml version="1.0" encoding="utf-8"?> | |
-<openerp> | |
- <data> | |
- | |
- | |
- <wizard | |
- id="wizard_invoice_settlement" | |
- keyword="client_action_multi" | |
- model="settlement" | |
- name="cc_commission.invoice_settlement" | |
- string="Create invoices"/> | |
- | |
- | |
- </data> | |
-</openerp> | |
diff --git a/sale_commission/stock_picking.py b/sale_commission/stock_picking.py | |
index 482df7a..063011a 100644 | |
--- a/sale_commission/stock_picking.py | |
+++ b/sale_commission/stock_picking.py | |
@@ -2,7 +2,8 @@ | |
############################################################################## | |
# | |
# OpenERP, Open Source Management Solution | |
-# Copyright (C) 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>). All Rights Reserved | |
+# Copyright (C) 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>). | |
+# All Rights Reserved | |
# $Id$ | |
# | |
# This program is free software: you can redistribute it and/or modify | |
@@ -19,37 +20,43 @@ | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# | |
############################################################################## | |
+from openerp import models, fields | |
-"""Modificamos la creación de factura desde albarán para incluir el comportamiento de comisiones""" | |
-from osv import orm, fields | |
+class product_product(models.Model): | |
- | |
-class product_product(orm.Model): | |
_inherit = 'product.product' | |
- _columns = { | |
- 'commission_exent': fields.boolean('Commission exent') | |
- } | |
- _defaults = { | |
- 'commission_exent': False, | |
- } | |
+ | |
+ commission_exent = fields.Boolean( | |
+ string="Commission exent", | |
+ default=False | |
+ ) | |
-class stock_picking(orm.Model): | |
- """Modificamos la creación de factura desde albarán para incluir el comportamiento de comisiones""" | |
+class stock_picking(models.Model): | |
_inherit = 'stock.picking' | |
- _columns = { | |
- 'agent_ids': fields.many2many('sale.agent', 'sale_agent_clinic_rel', 'agent_id', 'clinic_id', 'Agentes') | |
- } | |
- def _invoice_line_hook(self, cr, uid, move_line, invoice_line_id, context=None): | |
+ agent_ids = fields.Many2many( | |
+ "sale.agent", | |
+ string="Agents" | |
+ ) | |
+ | |
+ 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: | |
+ super(stock_picking, self)._invoice_line_hook( | |
+ cr, uid, | |
+ move_line, | |
+ invoice_line_id, | |
+ context=context | |
+ ) | |
+ | |
+ exent = move_line.sale_line_id.product_id.commission_exent | |
+ if move_line and move_line.sale_line_id and not exent: | |
so_ref = move_line.sale_line_id.order_id | |
for so_agent_id in so_ref.sale_agent_ids: | |
vals = { | |
@@ -58,5 +65,9 @@ class stock_picking(orm.Model): | |
'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) | |
+ line_agent_id = agent_pool.create( | |
+ cr, uid, vals, context=context | |
+ ) | |
+ agent_pool.calculate_commission( | |
+ cr, uid, [line_agent_id], context=context | |
+ ) | |
diff --git a/sale_commission/stock_picking_view.xml b/sale_commission/stock_picking_view.xml | |
index 91d08fc..8f9c4bd 100644 | |
--- a/sale_commission/stock_picking_view.xml | |
+++ b/sale_commission/stock_picking_view.xml | |
@@ -6,18 +6,17 @@ | |
<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> | |
@@ -35,4 +34,4 @@ | |
</record--> | |
</data> | |
-</openerp> | |
\ No newline at end of file | |
+</openerp> | |
diff --git a/sale_commission/wizard/__init__.py b/sale_commission/wizard/__init__.py | |
index 4fa6987..291e352 100644 | |
--- a/sale_commission/wizard/__init__.py | |
+++ b/sale_commission/wizard/__init__.py | |
@@ -19,5 +19,5 @@ | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# | |
############################################################################## | |
- | |
-import wizard_invoice | |
+from . import wizard_invoice | |
+from . import wizard_settle | |
diff --git a/sale_commission/wizard/wizard_invoice.py b/sale_commission/wizard/wizard_invoice.py | |
index 00250d8..b5824bc 100644 | |
--- a/sale_commission/wizard/wizard_invoice.py | |
+++ b/sale_commission/wizard/wizard_invoice.py | |
@@ -2,7 +2,8 @@ | |
############################################################################## | |
# | |
# OpenERP, Open Source Management Solution | |
-# Copyright (C) 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>). All Rights Reserved | |
+# Copyright (C) 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>). | |
+# All Rights Reserved | |
# $Id$ | |
# | |
# This program is free software: you can redistribute it and/or modify | |
@@ -19,21 +20,28 @@ | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# | |
############################################################################## | |
+from openerp import models, fields, _ | |
+from openerp import exceptions | |
-from osv import fields, orm, osv | |
-from tools.translate import _ | |
- | |
-class settled_invoice_wizard (orm.TransientModel): | |
+class settled_invoice_wizard(models.TransientModel): | |
"""settled.invoice.wizard""" | |
_name = 'settled.invoice.wizard' | |
- _columns = { | |
- 'journal_id': fields.many2one('account.journal', 'Target journal', required=True, select=1), | |
- 'product_id': fields.many2one('product.product', 'Product for account', required=True, select=1), | |
- } | |
- _defaults = { | |
- } | |
+ | |
+ journal_id = fields.Many2one( | |
+ 'account.journal', | |
+ 'Target journal', | |
+ required=True, | |
+ select=1 | |
+ ) | |
+ | |
+ product_id = fields.Many2one( | |
+ 'product.product', | |
+ 'Product for account', | |
+ required=True, | |
+ select=1 | |
+ ) | |
def create_invoice(self, cr, uid, ids, context=None): | |
if context is None: | |
@@ -42,16 +50,32 @@ class settled_invoice_wizard (orm.TransientModel): | |
settlement_obj = self.pool.get('settlement') | |
for o in self.browse(cr, uid, ids, context=context): | |
res = settlement_obj.action_invoice_create( | |
- cr, uid, context['active_ids'], journal_id=o.journal_id.id, product_id=o.product_id.id, context=context) | |
+ cr, uid, | |
+ context['active_ids'], | |
+ journal_id=o.journal_id.id, | |
+ product_id=o.product_id.id, | |
+ context=context | |
+ ) | |
invoice_ids = res.values() | |
action = {} | |
if not invoice_ids[0]: | |
- raise osv.except_osv(_('Error'), _('No Invoices were created')) | |
- #change state settlement | |
- settlement_obj.write(cr, uid, context['active_ids'], {'state': 'invoiced'}, context=context) | |
- action_model, action_id = data_pool.get_object_reference(cr, uid, 'account', "action_invoice_tree2") | |
+ raise exceptions.Warning(_('No Invoices were created')) | |
+ # change state settlement | |
+ settlement_obj.write( | |
+ cr, uid, | |
+ context['active_ids'], | |
+ {'state': 'invoiced'}, | |
+ context=context | |
+ ) | |
+ action_model, action_id = data_pool.get_object_reference( | |
+ cr, uid, | |
+ 'account', | |
+ "action_invoice_tree2" | |
+ ) | |
if action_model: | |
action_pool = self.pool.get(action_model) | |
action = action_pool.read(cr, uid, action_id, context=context) | |
- action['domain'] = "[('id','in', [" + ','.join(map(str, invoice_ids[0])) + "])]" | |
+ action['domain'] = "[('id','in', [{}])]".format( | |
+ ','.join(map(str, invoice_ids[0])) | |
+ ) | |
return action | |
diff --git a/sale_commission/wizard/wizard_invoice.xml b/sale_commission/wizard/wizard_invoice.xml | |
index b7b72a4..7820281 100644 | |
--- a/sale_commission/wizard/wizard_invoice.xml | |
+++ b/sale_commission/wizard/wizard_invoice.xml | |
@@ -1,19 +1,28 @@ | |
<?xml version="1.0" encoding="UTF-8"?> | |
<openerp> | |
<data> | |
- <record id="view_settled_invoice" model="ir.ui.view"> | |
+ | |
+ <record id="view_settled_invoice" model="ir.ui.view"> | |
<field name="name">Make invoices</field> | |
<field name="model">settled.invoice.wizard</field> | |
<field name="arch" type="xml"> | |
- <form string="Create invoices"> | |
- <separator colspan="4" string="Create invoice" /> | |
- <field name="journal_id"/> | |
- <newline/> | |
- <field name="product_id"/> | |
- <newline/> | |
- <button special="cancel" string="_Cancel" icon='gtk-cancel'/> | |
- <button name="create_invoice" string="Create" type="object" icon="terp-gtk-go-back-rtl"/> | |
- </form> | |
+ <form string="Create invoices"> | |
+ <group> | |
+ <field name="product_id" /> | |
+ <field name="journal_id" /> | |
+ </group> | |
+ <footer> | |
+ | |
+ <button name="create_invoice" | |
+ string="Create" | |
+ type="object" | |
+ class="oe_highlight" /> | |
+ or | |
+ <button special="cancel" | |
+ string="_Cancel" | |
+ class="oe_link" /> | |
+ </footer> | |
+ </form> | |
</field> | |
</record> | |
@@ -26,6 +35,8 @@ | |
view_mode="form" | |
view_type="form" | |
target="new" | |
- id="action_settled_invoice"/> | |
- </data> | |
- </openerp> | |
+ id="action_settled_invoice" | |
+ /> | |
+ | |
+ </data> | |
+</openerp> | |
diff --git a/sale_commission/wizard/wizard_settle.py b/sale_commission/wizard/wizard_settle.py | |
new file mode 100644 | |
index 0000000..c1e3821 | |
--- /dev/null | |
+++ b/sale_commission/wizard/wizard_settle.py | |
@@ -0,0 +1,114 @@ | |
+# -*- coding: utf-8 -*- | |
+############################################################################## | |
+# | |
+# OpenERP, Open Source Management Solution | |
+# Copyright (C) 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>). | |
+# All Rights Reserved | |
+# $Id$ | |
+# | |
+# This program is free software: you can redistribute it and/or modify | |
+# it under the terms of the GNU General Public License as published by | |
+# the Free Software Foundation, either version 3 of the License, or | |
+# (at your option) any later version. | |
+# | |
+# This program is distributed in the hope that it will be useful, | |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
+# GNU General Public License for more details. | |
+# | |
+# You should have received a copy of the GNU General Public License | |
+# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
+# | |
+############################################################################## | |
+from openerp import models, fields | |
+ | |
+ | |
+class settled_wizard (models.TransientModel): | |
+ """settled.wizard""" | |
+ | |
+ _name = "settled.wizard" | |
+ | |
+ date_from = fields.Date('From', required=True) | |
+ date_to = fields.Date('To', required=True) | |
+ | |
+ def settlement_exec(self, cr, uid, ids, context=None): | |
+ """se ejecuta correctamente desde dos.""" | |
+ if context is None: | |
+ context = {} | |
+ pool_liq = self.pool.get('settlement') | |
+ for o in self.browse(cr, uid, ids, context=context): | |
+ vals = { | |
+ 'name': o.date_from + " // " + o.date_to, | |
+ 'date_from': o.date_from, | |
+ 'date_to': o.date_to | |
+ } | |
+ liq_id = pool_liq.create(cr, uid, vals, context=context) | |
+ pool_liq.calculate( | |
+ cr, uid, liq_id, | |
+ context['active_ids'], | |
+ o.date_from, | |
+ o.date_to, | |
+ context=context | |
+ ) | |
+ | |
+ return { | |
+ 'type': 'ir.actions.act_window_close', | |
+ } | |
+ | |
+ def action_cancel(self, cr, uid, ids, connect=None, context=None): | |
+ """Cancel Liquidation""" | |
+ return { | |
+ 'type': 'ir.actions.act_window_close', | |
+ } | |
+ | |
+ | |
+class recalculate_commission_wizard(models.TransientModel): | |
+ """settled.wizard""" | |
+ | |
+ _name = "recalculate.commission.wizard" | |
+ | |
+ date_from = fields.Date(string="From", required=True) | |
+ date_to = fields.Date(string="To", required=True) | |
+ | |
+ def recalculate_exec(self, cr, uid, ids, context=None): | |
+ """se ejecuta correctamente desde dos.""" | |
+ if context is None: | |
+ context = {} | |
+ user = self.pool.get('res.users').browse(cr, uid, uid, context=context) | |
+ agent_pool = self.pool.get('invoice.line.agent') | |
+ for o in self.browse(cr, uid, ids, context=context): | |
+ sql = """ | |
+ SELECT invoice_line_agent.id FROM account_invoice_line | |
+ INNER JOIN invoice_line_agent | |
+ ON invoice_line_agent.invoice_line_id=account_invoice_line.id | |
+ INNER JOIN account_invoice | |
+ ON account_invoice_line.invoice_id = account_invoice.id | |
+ WHERE | |
+ invoice_line_agent.agent_id in ({}) | |
+ AND invoice_line_agent.settled=False | |
+ AND account_invoice.state<>'draft' | |
+ AND account_invoice.type='out_invoice' | |
+ AND account_invoice.date_invoice >= '{}' | |
+ AND account_invoice.date_invoice <= '{}' | |
+ AND account_invoice.company_id = {} | |
+ """.format( | |
+ ",".join(map(str, context['active_ids'])), | |
+ o.date_from, | |
+ o.date_to, | |
+ user.company_id.id | |
+ ) | |
+ cr.execute(sql) | |
+ res = cr.fetchall() | |
+ inv_line_agent_ids = [x[0] for x in res] | |
+ agent_pool.calculate_commission( | |
+ cr, uid, inv_line_agent_ids, context=context | |
+ ) | |
+ return { | |
+ 'type': 'ir.actions.act_window_close', | |
+ } | |
+ | |
+ def action_cancel(self, cr, uid, ids, connect=None, context=None): | |
+ """Cancel Calculation""" | |
+ return { | |
+ 'type': 'ir.actions.act_window_close', | |
+ } | |
diff --git a/sale_commission/wizard/wizard_settle.xml b/sale_commission/wizard/wizard_settle.xml | |
new file mode 100644 | |
index 0000000..0b50353 | |
--- /dev/null | |
+++ b/sale_commission/wizard/wizard_settle.xml | |
@@ -0,0 +1,68 @@ | |
+<?xml version="1.0"?> | |
+<openerp> | |
+ <data> | |
+ | |
+ <record id="view_settled_wizard" model="ir.ui.view"> | |
+ <field name="name">Select period to settle</field> | |
+ <field name="model">settled.wizard</field> | |
+ <field name="arch" type="xml"> | |
+ <form string="Select period to Settle"> | |
+ <group> | |
+ <field name="date_from" /> | |
+ <field name="date_to" /> | |
+ </group> | |
+ <footer> | |
+ <button name="settlement_exec" | |
+ string="Run Settlement Agents" | |
+ type="object" | |
+ class="oe_highlight" /> | |
+ or | |
+ <button | |
+ name="action_cancel" | |
+ string="Cancel" | |
+ class="oe_link" | |
+ special="cancel" | |
+ /> | |
+ </footer> | |
+ </form> | |
+ </field> | |
+ </record> | |
+ | |
+ | |
+ <act_window id="action_agents_settlement" | |
+ name="Perform agents settlements" | |
+ res_model="settled.wizard" | |
+ src_model="sale.agent" | |
+ multi="True" | |
+ view_mode="form" | |
+ view_type="form" | |
+ target="new" /> | |
+ | |
+ | |
+ <record id="view_recalculate_commision_wizard" model="ir.ui.view"> | |
+ <field name="name">Select period to recalculate</field> | |
+ <field name="model">recalculate.commission.wizard</field> | |
+ <field name="arch" type="xml"> | |
+ <form string="Select period to recalculate commissions"> | |
+ <group> | |
+ <field name="date_from" /> | |
+ <field name="date_to" /> | |
+ </group> | |
+ <footer> | |
+ <button name="recalculate_exec" | |
+ string="Recalculate agents commissions" | |
+ type="object" | |
+ class="oe_highlight" /> | |
+ or | |
+ <button | |
+ name="action_cancel" | |
+ string="Cancel" | |
+ class="oe_link" | |
+ special="cancel" /> | |
+ </footer> | |
+ </form> | |
+ </field> | |
+ </record> | |
+ | |
+ </data> | |
+</openerp> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment