[ADD] stock_landed_costs : Added the stock_landed_costs module.

bzr revid: mdi@tinyerp.com-20140408113935-67fykki3056w8hr8
This commit is contained in:
DJ Patel 2014-04-08 17:09:35 +05:30
parent b14883f10c
commit d0dbdf8082
6 changed files with 368 additions and 0 deletions

View File

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# 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 product
import stock_landed_costs
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# 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/>.
#
##############################################################################
{
'name': 'WMS Landed Costs',
'version': '1.1',
'author': 'OpenERP SA',
'summary': 'Landed Costs',
'description': """
#TODO
======================
#TODO
""",
'website': 'http://www.openerp.com',
'images': [],
'depends': ['stock_account'],
'category': 'Hidden',
'sequence': 16,
'demo': [
],
'data': [
'product_view.xml',
'stock_landed_costs_view.xml',
],
'test': [
],
'installable': True,
'application': True,
'auto_install': True,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# 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 openerp.osv import fields, osv
SPLIT_METHOD = [
('equal', 'Equal'),
('by_quantity', 'By Quantity'),
('by_current_cost_price', 'By Current Cost Price'),
('by_weight', 'By Weight'),
('by_volume', 'By Volume'),
]
class product_product(osv.osv):
_inherit = "product.product"
_columns = {
'landed_cost_ok': fields.boolean('Can constitute a landed cost'),
'split_method': fields.selection(SPLIT_METHOD, 'Split Method'),
}
_defaults = {
'landed_cost_ok': False,
'split_method': 'equal',
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_product_landed_cost_form" model="ir.ui.view">
<field name="name">product.product.landed.cost.form</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view"/>
<field name="arch" type="xml">
<div name="options" position="inside">
<field name="landed_cost_ok"/>
<label for="landed_cost_ok"/>
</div>
<xpath expr="//group[@name='properties']" position="before">
<group>
<separator string="Split Method" colspan="4"/>
<group colspan="2" col="2">
<field name="split_method"/>
</group>
</group>
</xpath>
</field>
</record>
</data>
</openerp>

View File

@ -0,0 +1,112 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# 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 time
from openerp.osv import fields, osv
import openerp.addons.decimal_precision as dp
import product
class stock_landed_cost(osv.osv):
_name = 'stock.landed.cost'
_description = 'Stock Landed Cost'
def _total_amount(self, cr, uid, ids, name, args, context=None):
result = {}
for cost in self.browse(cr, uid, ids, context=context):
total = 0.0
for line in cost.cost_lines:
total += line.price_subtotal
result[cost.id] = total
return result
def _get_cost_line(self, cr, uid, ids, context=None):
result = {}
for line in self.pool.get('stock.landed.cost.lines').browse(cr, uid, ids, context=context):
result[line.cost_id.id] = True
return result.keys()
_columns = {
'name': fields.char('Name', size=256, required=True),
'date': fields.datetime('Date', required=True),
'picking_ids': fields.many2many('stock.picking', string='Pickings'),
'cost_lines': fields.one2many('stock.landed.cost.lines', 'cost_id', 'Cost Lines'),
'description': fields.text('Item Description'),
'amount_total': fields.function(_total_amount, type='float', string='Total', digits_compute=dp.get_precision('Account'),
store={
'stock.landed.cost': (lambda self, cr, uid, ids, c={}: ids, ['cost_lines'], 20),
'stock.landed.cost.lines': (_get_cost_line, ['price_unit', 'quantity', 'cost_id'], 20),
}
),
'state':fields.selection([('draft', 'Draft'), ('open', 'Open'), ('cancel', 'Cancelled')], 'State', readonly=True),
}
_defaults = {
'state': 'draft',
'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
}
def button_validate(self, cr ,uid, ids, context=None):
return True
def button_cancel(self, cr ,uid, ids, context=None):
return True
class stock_landed_cost_lines(osv.osv):
_name = 'stock.landed.cost.lines'
_description = 'Stock Landed Cost Lines'
def _amount_subtotal(self, cr, uid, ids, name, args, context=None):
result = {}
for line in self.browse(cr, uid, ids, context=context):
result[line.id] = (line.quantity * line.price_unit)
return result
def onchange_product_id(self, cr, uid, ids, product_id=False, quantity=0.0, uom_id=False, price_unit=0.0, account_id=False, context=None):
result = {}
if not product_id:
return {'value': {'quantity': 0.0, 'uom_id': False, 'price_unit': 0.0}}
product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
result['name'] = product.name
result['split_method'] = product.split_method
result['price_unit'] = product.standard_price
result['uom_id'] = product.uom_id.id
return {'value': result}
_columns = {
'name': fields.char('Description', size=256),
'cost_id': fields.many2one('stock.landed.cost', 'Landed Cost', required=True, ondelete='cascade'),
'product_id': fields.many2one('product.product', 'Product', required=True),
'uom_id': fields.many2one('product.uom', 'Unit of Measure', ondelete='set null', select=True),
'quantity': fields.float('Quantity', digits_compute= dp.get_precision('Product Unit of Measure'), required=True),
'price_unit': fields.float('Unit Price', required=True, digits_compute= dp.get_precision('Product Price')),
'split_method': fields.selection(product.SPLIT_METHOD, string='Split Method'),
'account_id': fields.many2one('account.account', 'Account', domain=[('type','<>','view'), ('type', '<>', 'closed')]),
'price_subtotal': fields.function(_amount_subtotal, string='Amount', type='float', digits_compute= dp.get_precision('Account'), store=True),
}
_defaults = {
'quantity': 1.0,
'split_method': 'equal',
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<!-- Stock Landed Cost Form View -->
<record id='view_stock_landed_cost_form' model='ir.ui.view'>
<field name="name">stock.landed.cost.form</field>
<field name="model">stock.landed.cost</field>
<field name="arch" type="xml">
<form string="Landed Costs" version="7.0">
<header>
<button name="button_validate" string="Validate" states="draft" class="oe_highlight" type="object"/>
<button name="button_cancel" string="Cancel" states="draft" type="object"/>
<field name="state" widget="statusbar" statusbar_visible="draft,open" statusbar_colors='{"reject":"cancel"}'/>
</header>
<sheet>
<div class="oe_title">
<label for="name" class="oe_edit_only"/>
<h1>
<field name="name" class="oe_inline"/>
</h1>
</div>
<group>
<group>
<field name="date"/>
</group>
<group>
<field name="picking_ids" widget="many2many_tags"/>
</group>
</group>
<notebook>
<page string="Cost Lines">
<field name="cost_lines">
<form string="Cost Lines" version="7.0">
<group>
<group>
<field name="product_id"
on_change="onchange_product_id(product_id, quantity, uom_id, price_unit, account_id)"/>
<label for="product_uom_qty"/>
<div>
<field name="quantity" class="oe_inline"/>
<field name="uom_id" groups="product.group_uom" class="oe_inline oe_no_button"/>
</div>
<field name="price_unit"/>
</group>
<group>
<field name="split_method"/>
<field name="account_id"/>
</group>
</group>
<label for="name"/>
<field name="name"/>
</form>
<tree string="Cost Lines">
<field name="product_id" on_change="onchange_product_id(product_id, quantity, uom_id, price_unit, account_id)"/>
<field name="name"/>
<field name="account_id"/>
<field name="split_method"/>
<field name="quantity"/>
<field name="uom_id"/>
<field name="price_unit"/>
<field name="price_subtotal"/>
</tree>
</field>
<group class="oe_subtotal_footer oe_right">
<field name="amount_total"/>
</group>
</page>
</notebook>
<div class="oe_clear">
<label for="description"/>
</div>
<field name="description" class="oe_inline" placeholder="Additional note..."/>
</sheet>
</form>
</field>
</record>
<!-- Stock Landed Cost Tree View -->
<record id='view_stock_landed_cost_tree' model='ir.ui.view'>
<field name="name">stock.landed.cost.tree</field>
<field name="model">stock.landed.cost</field>
<field name="arch" type="xml">
<tree string="Landed Costs">
<field name="name"/>
<field name="date"/>
</tree>
</field>
</record>
<!-- Stock Landed Cost Action -->
<record id='action_stock_landed_cost' model='ir.actions.act_window'>
<field name="name">Landed Costs</field>
<field name="res_model">stock.landed.cost</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{}</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create a new landed cost.
</p>
</field>
</record>
<!-- Stock Landed Cost Menu -->
<menuitem name="Landed Costs" parent="stock.menu_stock_root" id="menu_stock_landed_cost_main" sequence="0"/>
<menuitem action="action_stock_landed_cost" name="Landed Costs" parent="menu_stock_landed_cost_main" id="menu_stock_landed_cost" sequence="1"/>
</data>
</openerp>