From d0dbdf80824592548592ef6f051b457e4dd8363d Mon Sep 17 00:00:00 2001 From: DJ Patel Date: Tue, 8 Apr 2014 17:09:35 +0530 Subject: [PATCH] [ADD] stock_landed_costs : Added the stock_landed_costs module. bzr revid: mdi@tinyerp.com-20140408113935-67fykki3056w8hr8 --- addons/stock_landed_costs/__init__.py | 25 ++++ addons/stock_landed_costs/__openerp__.py | 50 ++++++++ addons/stock_landed_costs/product.py | 45 +++++++ addons/stock_landed_costs/product_view.xml | 26 ++++ .../stock_landed_costs/stock_landed_costs.py | 112 ++++++++++++++++++ .../stock_landed_costs_view.xml | 110 +++++++++++++++++ 6 files changed, 368 insertions(+) create mode 100644 addons/stock_landed_costs/__init__.py create mode 100644 addons/stock_landed_costs/__openerp__.py create mode 100644 addons/stock_landed_costs/product.py create mode 100644 addons/stock_landed_costs/product_view.xml create mode 100644 addons/stock_landed_costs/stock_landed_costs.py create mode 100644 addons/stock_landed_costs/stock_landed_costs_view.xml diff --git a/addons/stock_landed_costs/__init__.py b/addons/stock_landed_costs/__init__.py new file mode 100644 index 00000000000..8d9926454f9 --- /dev/null +++ b/addons/stock_landed_costs/__init__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# 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 . +# +############################################################################## + +import product +import stock_landed_costs + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/stock_landed_costs/__openerp__.py b/addons/stock_landed_costs/__openerp__.py new file mode 100644 index 00000000000..b8d11ae77cd --- /dev/null +++ b/addons/stock_landed_costs/__openerp__.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# 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 . +# +############################################################################## + +{ + '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: diff --git a/addons/stock_landed_costs/product.py b/addons/stock_landed_costs/product.py new file mode 100644 index 00000000000..93e2ec3547c --- /dev/null +++ b/addons/stock_landed_costs/product.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# 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 . +# +############################################################################## + +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: diff --git a/addons/stock_landed_costs/product_view.xml b/addons/stock_landed_costs/product_view.xml new file mode 100644 index 00000000000..7e5d2826504 --- /dev/null +++ b/addons/stock_landed_costs/product_view.xml @@ -0,0 +1,26 @@ + + + + + + product.product.landed.cost.form + product.product + + +
+ +
+ + + + + + + + +
+
+ +
+
diff --git a/addons/stock_landed_costs/stock_landed_costs.py b/addons/stock_landed_costs/stock_landed_costs.py new file mode 100644 index 00000000000..981ce6191c7 --- /dev/null +++ b/addons/stock_landed_costs/stock_landed_costs.py @@ -0,0 +1,112 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# 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 . +# +############################################################################## + +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: diff --git a/addons/stock_landed_costs/stock_landed_costs_view.xml b/addons/stock_landed_costs/stock_landed_costs_view.xml new file mode 100644 index 00000000000..d5e4349593d --- /dev/null +++ b/addons/stock_landed_costs/stock_landed_costs_view.xml @@ -0,0 +1,110 @@ + + + + + + + stock.landed.cost.form + stock.landed.cost + +
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+
+ + + + stock.landed.cost.tree + stock.landed.cost + + + + + + + + + + + Landed Costs + stock.landed.cost + form + tree,form + {} + +

+ Click to create a new landed cost. +

+
+
+ + + + + +
+