|
@@ -0,0 +1,266 @@
|
|
|
+# -*- encoding: utf-8 -*-
|
|
|
+#################################################################################
|
|
|
+# #
|
|
|
+# product_features for OpenERP #
|
|
|
+# Copyright (C) 2009 NetAndCo (<http://www.netandco.net>). #
|
|
|
+# Authors, Mathieu Lemercier, mathieu@netandco.net, #
|
|
|
+# Franck Bret, franck@netandco.net #
|
|
|
+# Copyright (C) 2011 Akretion Benoît Guillot <benoit.guillot@akretion.com> #
|
|
|
+# #
|
|
|
+# 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 import models, fields, api, _
|
|
|
+import openerp.addons.decimal_precision as dp
|
|
|
+
|
|
|
+class sale_nota_remision(models.Model):
|
|
|
+ _name = "sale.nota.remision"
|
|
|
+ _description = "Sales Order Reference Note"
|
|
|
+
|
|
|
+ def validar(self):
|
|
|
+ print 'Confirmar'
|
|
|
+ self.state = 'progress'
|
|
|
+ return True
|
|
|
+
|
|
|
+ #data fields for partner
|
|
|
+ @api.multi
|
|
|
+ @api.depends('partner_id')
|
|
|
+ def _partner_data(self):
|
|
|
+ self.partner_ruc = self.partner_id.ruc
|
|
|
+ self.partner_phone = self.partner_id.phone
|
|
|
+ self.partner_mobile = self.partner_id.mobile
|
|
|
+ self.partner_company = self.partner_id.company_id.id
|
|
|
+
|
|
|
+ #data fields for salesman
|
|
|
+ @api.multi
|
|
|
+ @api.depends('user_id')
|
|
|
+ def _user_data(self):
|
|
|
+ self.user_ruc = self.user_id.ruc
|
|
|
+ self.user_phone = self.user_id.phone
|
|
|
+ self.user_mobile = self.user_id.mobile
|
|
|
+
|
|
|
+ #data fields for vehicle
|
|
|
+ # @api.multi
|
|
|
+ # @api.depends('vehicle_id')
|
|
|
+ # def _vehicle_data(self):
|
|
|
+ # self.vehicle_plate = self.vehicle_id.license_plate
|
|
|
+ # self.driver_id = self.vehicle_id.driver_id
|
|
|
+
|
|
|
+ #data fields for driver
|
|
|
+ @api.multi
|
|
|
+ @api.depends('driver_id')
|
|
|
+ def _driver_data(self):
|
|
|
+ self.driver_ruc = self.driver_id.ruc
|
|
|
+ self.driver_phone = self.driver_id.phone
|
|
|
+ self.driver_mobile = self.driver_id.mobile
|
|
|
+
|
|
|
+ #data fields for logistic
|
|
|
+ @api.multi
|
|
|
+ @api.depends('logistic_company_id')
|
|
|
+ def _logistic_data(self):
|
|
|
+ self.logistic_ruc = self.logistic_company_id.ruc
|
|
|
+ self.logistic_phone = self.logistic_company_id.phone
|
|
|
+ self.logistic_mobile = self.logistic_company_id.mobile
|
|
|
+
|
|
|
+ @api.model
|
|
|
+ def create(self, vals):
|
|
|
+ nota_id = super(sale_nota_remision,self).create(vals)
|
|
|
+ # vals['name']=self.pool.get('ir.sequence').get(cr, uid, 'sale.order') or '/'
|
|
|
+ nota_id.name=self.pool.get('ir.sequence').get(self.env.cr, self.env.uid, 'sale.nota.remision') or '/'
|
|
|
+ return nota_id
|
|
|
+
|
|
|
+
|
|
|
+ # fields
|
|
|
+ name = fields.Char(string='Reference/Description', index=True, readonly=True)
|
|
|
+ origin = fields.Char(string='Source Document', help="Reference of the document that produced this note.", readonly=True)
|
|
|
+
|
|
|
+ #partner data
|
|
|
+ partner_id = fields.Many2one('res.partner', string='Partner', required=True)
|
|
|
+ partner_ruc = fields.Char(string='R.U.C./C.I.',compute='_partner_data')
|
|
|
+ partner_phone = fields.Char(string='Teléfono',compute='_partner_data')
|
|
|
+ partner_mobile = fields.Char(string='Telef. Móvil',compute='_partner_data')
|
|
|
+ #company address
|
|
|
+ partner_company = fields.Many2one('res.company', string='Company')
|
|
|
+
|
|
|
+ #commercial data
|
|
|
+ user_id = fields.Many2one('res.users', 'Salesperson', select=True)
|
|
|
+ user_ruc = fields.Char(string='R.U.C./C.I. Salesperson',compute='_user_data')
|
|
|
+ user_phone = fields.Char(string='Teléfono',compute='_user_data')
|
|
|
+ user_mobile = fields.Char(string='Telef. Móvil',compute='_user_data')
|
|
|
+
|
|
|
+ #logistic data
|
|
|
+ logistic_company_id = fields.Many2one('res.partner', 'Logistic Company', select=True)
|
|
|
+ logistic_ruc = fields.Char(string='R.U.C./C.I. Logistic Company',compute='_logistic_data')
|
|
|
+ logistic_phone = fields.Char(string='Teléfono',compute='_logistic_data')
|
|
|
+ logistic_mobile = fields.Char(string='Telef. Móvil',compute='_logistic_data')
|
|
|
+
|
|
|
+ state = fields.Selection(
|
|
|
+ [('cancel', 'Cancelled'),('draft', 'Draft'),('progress', 'Progress'),('done', 'Done')],
|
|
|
+ 'Status', required=True, readonly=True, copy=False,
|
|
|
+ help='* The \'Draft\' status is set when the related note order in draft status. \
|
|
|
+ \n* The \'Progress\' status is set when the related note order is in progress. \
|
|
|
+ \n* The \'Done\' status is set when the note order line has been picked. \
|
|
|
+ \n* The \'Cancelled\' status is set when a user cancel the note order related.')
|
|
|
+
|
|
|
+ #Transfer details
|
|
|
+ initial_transfer_date = fields.Datetime('Initial Transfer Date')
|
|
|
+ finish_transfer_date = fields.Datetime('Finish Transfer Date')
|
|
|
+
|
|
|
+ #Vehicle and Logistic details
|
|
|
+ vehicle_name = fields.Char('Vehicle')
|
|
|
+ vehicle_plate = fields.Char('Nro. de la Chapa')
|
|
|
+
|
|
|
+ #Driver details
|
|
|
+ driver_id = fields.Many2one('res.partner','Driver')
|
|
|
+ driver_ruc = fields.Char(string='R.U.C./C.I. Driver',compute='_driver_data')
|
|
|
+ driver_phone = fields.Char(string='Teléfono',compute='_driver_data')
|
|
|
+ driver_mobile = fields.Char(string='Telef. Móvil',compute='_driver_data')
|
|
|
+
|
|
|
+ #Transfer motives
|
|
|
+ is_sale = fields.Boolean('Sale:')
|
|
|
+ is_purchase = fields.Boolean('Purchase:')
|
|
|
+ is_export = fields.Boolean('Export:')
|
|
|
+ is_import= fields.Boolean('Import:')
|
|
|
+ is_consignment = fields.Boolean('Consignment:')
|
|
|
+ is_return = fields.Boolean('Return:')
|
|
|
+ is_intertal_transfer = fields.Boolean('Internal Transfer between stores:')
|
|
|
+ is_transformation_transfer = fields.Boolean('Transformation Transfer:')
|
|
|
+ is_repair_transfer = fields.Boolean('Repair Transfer:')
|
|
|
+ is_movil_transfer = fields.Boolean('Movil Transfer:')
|
|
|
+ is_exhibition = fields.Boolean('Exhibition/Demonstration:')
|
|
|
+ is_fair = fields.Boolean('Fair Participation:')
|
|
|
+
|
|
|
+ another_transfer = fields.Text('Another Transfer motive')
|
|
|
+ sale_voucher = fields.Char('Sale Voucher')
|
|
|
+
|
|
|
+ nota_line = fields.One2many('sale.nota.remision.line', 'nota_remision_id', 'Note Lines', readonly=True, states={'draft': [('readonly', False)]}, copy=True)
|
|
|
+ amount_total = fields.Float('Amount Total',readonly=True)
|
|
|
+
|
|
|
+ _defaults = {
|
|
|
+ 'state': 'draft',
|
|
|
+ 'is_consignment': True,
|
|
|
+ 'name': lambda obj, cr, uid, context: '/',
|
|
|
+ }
|
|
|
+
|
|
|
+class sale_nota_remision_line(models.Model):
|
|
|
+ _name = 'sale.nota.remision.line'
|
|
|
+ _description = "Sales Order Reference Note Line"
|
|
|
+
|
|
|
+ @api.one
|
|
|
+ @api.model
|
|
|
+ def _amount_line(self):
|
|
|
+ for line in self.ids:
|
|
|
+ line_obj = self.env['sale.nota.remision.line'].search([('id','=',line)])
|
|
|
+ price = line_obj.price_unit*(1 - (line_obj.discount or 0.0) / 100.0)
|
|
|
+ self.price_subtotal = price*line_obj.product_uom_qty
|
|
|
+
|
|
|
+ #fields
|
|
|
+ nota_remision_id = fields.Many2one('sale.nota.remision', 'Note Reference', required=True, ondelete='cascade', select=True, readonly=True, states={'draft':[('readonly',False)]})
|
|
|
+ name = fields.Text('Description', required=True, readonly=True, states={'draft': [('readonly', False)]})
|
|
|
+ product_id = fields.Many2one('product.product', 'Product', domain=[('sale_ok', '=', True)], change_default=True, readonly=True, states={'draft': [('readonly', False)]}, ondelete='restrict')
|
|
|
+ product_uom_qty = fields.Float('Quantity', digits_compute= dp.get_precision('Product UoS'), required=True, readonly=True, states={'draft': [('readonly', False)]})
|
|
|
+ price_unit = fields.Float('Unit Price', required=True, digits_compute= dp.get_precision('Product Price'), readonly=True, states={'draft': [('readonly', False)]})
|
|
|
+ discount = fields.Float('Discount (%)', digits_compute= dp.get_precision('Discount'), readonly=True, states={'draft': [('readonly', False)]})
|
|
|
+ price_subtotal = fields.Float(compute='_amount_line', string='Subtotal')
|
|
|
+ # price_subtotal = fields.Float(compute='_amount_line', string='Subtotal', digits_compute= dp.get_precision('Account'))
|
|
|
+ state = fields.Selection(
|
|
|
+ [('cancel', 'Cancelled'),('draft', 'Draft'),('progress', 'Progress'),('done', 'Done')],
|
|
|
+ 'Status', required=True, readonly=True, copy=False,
|
|
|
+ help='* The \'Draft\' status is set when the related note order in draft status. \
|
|
|
+ \n* The \'Progress\' status is set when the related note order is in progress. \
|
|
|
+ \n* The \'Done\' status is set when the note order line has been picked. \
|
|
|
+ \n* The \'Cancelled\' status is set when a user cancel the note order related.')
|
|
|
+
|
|
|
+ _order = 'nota_remision_id desc, id'
|
|
|
+ _defaults = {
|
|
|
+ 'state': 'draft',
|
|
|
+ }
|
|
|
+
|
|
|
+class sale_order(models.Model):
|
|
|
+ _name = 'sale.order'
|
|
|
+ _inherit = 'sale.order'
|
|
|
+
|
|
|
+ @api.multi
|
|
|
+ def _note_reference_exists(self):
|
|
|
+ print self.note_reference_ids
|
|
|
+ if self.note_reference_ids:
|
|
|
+ self.note_reference_exists=True
|
|
|
+ else:
|
|
|
+ self.note_reference_exists=False
|
|
|
+
|
|
|
+ note_reference_exists = fields.Boolean(string="Note exists", compute='_note_reference_exists', store="True")
|
|
|
+ note_reference_ids = fields.Many2one('sale.nota.remision', 'Reference Note')
|
|
|
+
|
|
|
+ @api.multi
|
|
|
+ def action_button_view_note(self):
|
|
|
+ # print 'Ver Nota'
|
|
|
+ return {
|
|
|
+ 'type': 'ir.actions.act_window',
|
|
|
+ 'res_model': 'sale.nota.remision',
|
|
|
+ 'view_type': 'form',
|
|
|
+ 'view_mode': 'form',
|
|
|
+ 'target': 'current',
|
|
|
+ 'res_id':self.note_reference_ids.id,
|
|
|
+ }
|
|
|
+
|
|
|
+ @api.multi
|
|
|
+ def action_button_create_note(self):
|
|
|
+ # print "Crear Nota de Remision"
|
|
|
+ # print self.partner_id.id
|
|
|
+
|
|
|
+ # print self
|
|
|
+
|
|
|
+ nsr = self.env['sale.nota.remision'].search([('origin','=',self.name)])
|
|
|
+ if not nsr:
|
|
|
+ valores = {'partner_id':self.partner_id.id,
|
|
|
+ 'origin':self.name,
|
|
|
+ 'initial_transfer_date':self.date_order,
|
|
|
+ 'user_id':self.user_id.id,
|
|
|
+ 'amount_total':self.amount_total,
|
|
|
+ 'partner_company':self.partner_id.company_id.id,
|
|
|
+ }
|
|
|
+
|
|
|
+ #crear la nota de remision
|
|
|
+
|
|
|
+ # print 'Nota creada'
|
|
|
+ nr = self.env['sale.nota.remision'].create(valores)
|
|
|
+ # print nr
|
|
|
+ if nr:
|
|
|
+ self.note_reference_ids=nr
|
|
|
+ self._note_reference_exists()
|
|
|
+ #copiar las lineas del pedido
|
|
|
+ for line in self.order_line:
|
|
|
+ # print line
|
|
|
+ # print line.product_id
|
|
|
+ line_order = self.env['sale.order.line'].search([('id','=',line.id)])
|
|
|
+ if line_order:
|
|
|
+ valores = {'nota_remision_id':nr[0].id,
|
|
|
+ 'product_id':line_order[0].product_id.id,
|
|
|
+ 'name':line_order[0].name,
|
|
|
+ 'product_uom_qty':line_order[0].product_uom_qty,
|
|
|
+ 'price_unit':line_order[0].price_unit,
|
|
|
+ 'discount':line_order[0].discount,
|
|
|
+ }
|
|
|
+
|
|
|
+ nrl = self.env['sale.nota.remision.line'].create(valores)
|
|
|
+
|
|
|
+ # else:
|
|
|
+ # print 'La Nota ya existe'
|
|
|
+
|
|
|
+ return True
|
|
|
+
|
|
|
+ _defaults = {
|
|
|
+ 'note_reference_exists':False,
|
|
|
+ }
|