Skip to content

Commit

Permalink
[WIP] started working on the wizard part. Not finished, disabled for now
Browse files Browse the repository at this point in the history
(lp:c2c-addons/6.1  rev 40.1.30)
  • Loading branch information
gurneyalex committed May 29, 2012
1 parent f84ec42 commit 4eafed5
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 5 deletions.
1 change: 1 addition & 0 deletions product_historical_margin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
##############################################################################

from . import product_historical_margin
##from . import wizard
4 changes: 3 additions & 1 deletion product_historical_margin/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
""",
'website': 'http://www.camptocamp.com/',
'init_xml': [],
'update_xml': ["account_invoice_view.xml"],
'update_xml': ["account_invoice_view.xml",
#"wizard/historical_margin_view.xml",
],
'demo_xml': [],
'tests': [],
'installable': True,
Expand Down
29 changes: 25 additions & 4 deletions product_historical_margin/product_historical_margin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,36 @@
#
##############################################################################

from osv.orm import Model
from openerp.osv.orm import Model
from osv import fields

import decimal_precision as dp

class product_product(Model):
_inherit = 'product.product'
# TODO: re-enable when the wizard is ready
## class product_product(Model):
## _inherit = 'product_product'
## def _compute_margin(self, cr, uid, ids, field_names, arg, context):
## res = {}
## for obj in self.browse(cr, uid, ids):
## product = obj.product_id
## res[obj.id] = self._compute_margin2(cr, uid, product.id, obj.discount, obj.price_unit)
## print res
## return res
## _columns = {
## 'margin_absolute': fields.function(_compute_margin, method=True,
## readonly=True, type='float',
## string='Margin (absolute)',
## multi='product_historical_margin',
## digits_compute=dp.get_precision('Account'),
## help="The margin on the product in absolute value"),
## 'margin_relative': fields.function(_compute_margin, method=True,
## readonly=True, type='float',
## string='Margin (%)',
## multi='product_historical_margin',
## digits_compute=dp.get_precision('Account'),
## help="The margin on the product in relative value"),
## }



class account_invoice_line(Model):
_inherit = 'account.invoice.line'
Expand Down
22 changes: 22 additions & 0 deletions product_historical_margin/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Alexandre Fayolle
# Copyright 2012 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from . import historical_margin
50 changes: 50 additions & 0 deletions product_historical_margin/wizard/historical_margin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Alexandre Fayolle
# Copyright 2012 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import datetime

from openerp.osv.orm import TransientModel
from openerp.osv import fields


class historical_margin(TransientModel):
_name = 'historical_margin'
_description = 'Product historical margin'
_columns = {
'start_date': fields.date('Start Date', help='Date of the first invoice to take into account. The earliest existing invoice will be used if left empty'),
'end_date': fields.date('End Date', help='Date of the last invoice to take into account. The latest existing invoice will be used if left empty')
}
_defaults = {
'start_date': lambda *a: datetime.date(datetime.date.today().year, 1, 1),
#'end_date': lambda *a: datetime.date.today(),
}

def historical_margin_open_window(self, cr, uid, ids, context=None):
"""
Open the historical margin view
"""
if context is None:
context = {}
wiz = self.read(cr, uid, ids, [], context)[0]
ctx = context.copy()
ctx['start_date'] = wiz.get('start_date')
ctx['end_date'] = wiz.get('end_date')
# XXX FIXME

39 changes: 39 additions & 0 deletions product_historical_margin/wizard/historical_margin_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>

<!-- XXX This file is not processed (not listed in __openerp__.py) -->
<openerp>
<data>
<record id="view_historical_margin" model="ir.ui.view">
<field name="name">historical_margin.form</field>
<field name="model">historical_margin</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Historical Margin">
<group colspan="4">
<field name="start_date" "/>
<field name="end_date"/>
</group>
<separator string="" colspan="4"/>
<group colspan="4" col="6">
<button icon="gtk-cancel" special="cancel" string="Cancel"/>
<button icon="terp-gtk-go-back-rtl" string="Compute margins" name="historical_margin_open_window" type="object"/>
</group>
</form>
</field>
</record>
<record id="action_historical_margin" model="ir.actions.act_window">
<field name="name">Product historical margine</field>
<field name="res_model">historical_margin</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_historical_margin"/>
<field name="target">new</field>
<field name="help">Display the historical margin of your products</field>
</record>
<menuitem icon="STOCK_INDENT" action="action_historical_margin"
id="menu_action_account_tree2"
parent="account.menu_finance_charts" />
</data>
</openerp>

0 comments on commit 4eafed5

Please sign in to comment.