| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 | # -*- 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 dpclass sale_nota_remision(models.Model):    _name = "sale.nota.remision"    _description = "Nota de referencia de orden de venta"    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='Referencia/Descripción', index=True, readonly=True)    origin = fields.Char(string='Documento Origen ', help="Referencia del documento que produjo esta nota.", readonly=True)    #partner data    partner_id = fields.Many2one('res.partner', string='Cliente', 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='Empresa')    #commercial data    user_id = fields.Many2one('res.users', 'Vendedor', select=True)    user_ruc = fields.Char(string='R.U.C./C.I. Vendedor',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', 'Compañia Logística', select=True)    logistic_ruc = fields.Char(string='R.U.C./C.I. Compañia Logística',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', 'Cancelado'),('draft', 'Borrador'),('progress', 'En progreso'),('done', 'Realizado')],                'Status', required=True, readonly=True, copy=False,                help='* El estado de \'Borrador\' se establece cuando la nota relacionada se ordena en estado de borrador. \                    \n* El estado de \'Progreso\' se establece cuando el orden de las notas relacionadas está en curso. \                    \n* El estado de \'Realizado\' se establece cuando se selecciona la línea de orden de nota.\                    \n* El estado \'Cancelado\' se establece cuando un usuario cancela el pedido de notas relacionado')    #Transfer details    initial_transfer_date = fields.Datetime('Fecha de transferencia inicial')    finish_transfer_date = fields.Datetime('Fecha de transferencia finalizada')    #Vehicle and Logistic details    vehicle_name = fields.Char('Vehículo')    vehicle_plate = fields.Char('Nro. de la Chapa')    #Driver details    driver_id = fields.Many2one('res.partner','Chófer')    driver_ruc = fields.Char(string='R.U.C./C.I. Chófer',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('Venta:')    is_purchase = fields.Boolean('Compra:')    is_export = fields.Boolean('Exportación:')    is_import= fields.Boolean('Importación:')    is_consignment = fields.Boolean('Consignación:')    is_return = fields.Boolean('Devolución:')    is_intertal_transfer = fields.Boolean('Transferencia interna entre almacenes:')    is_transformation_transfer = fields.Boolean('Transferencia de transformación:')    is_repair_transfer = fields.Boolean('Transferencia de reparación:')    is_movil_transfer = fields.Boolean('Transferencia Movil:')    is_exhibition = fields.Boolean('Exhibición/Demostración:')    is_fair = fields.Boolean('Participación justa:')    another_transfer = fields.Text('Otro motivo de transferencia')    sale_voucher = fields.Char('Recibo de venta')    obs_remision = fields.Text('Observación')    nota_line = fields.One2many('sale.nota.remision.line', 'nota_remision_id', 'Líneas de nota de remisión', readonly=True, states={'draft': [('readonly', False)]}, copy=True)    amount_total = fields.Float('Monto 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 = "Referencia de orden de venta"    @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', 'Nota Referencia', required=True, ondelete='cascade', select=True, readonly=True, states={'draft':[('readonly',False)]})    name = fields.Text('Descripción', required=True, readonly=True, states={'draft': [('readonly', False)]})    product_id = fields.Many2one('product.product', 'Producto', domain=[('sale_ok', '=', True)], change_default=True, readonly=True, states={'draft': [('readonly', False)]}, ondelete='restrict')    product_uom_qty = fields.Float('Cantidad', digits_compute= dp.get_precision('Product UoS'), required=True, readonly=True, states={'draft': [('readonly', False)]})    price_unit = fields.Float('Precio Unit.', required=True, digits_compute= dp.get_precision('Product Price'), readonly=True, states={'draft': [('readonly', False)]})    discount = fields.Float('Descuento (%)', 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', 'Cancelado'),('draft', 'Borrador'),('progress', 'En progreso'),('done', 'Realizado')],                '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="Nota existe", compute='_note_reference_exists', store="True")    note_reference_ids = fields.Many2one('sale.nota.remision', 'Referencia Nota')    @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,    }
 |