diff --git a/stock_picking_deposito/models/res_partner.py b/stock_picking_deposito/models/res_partner.py index 2f29669..3e46aa2 100644 --- a/stock_picking_deposito/models/res_partner.py +++ b/stock_picking_deposito/models/res_partner.py @@ -2,12 +2,12 @@ # @author: Criptomart () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -#import logging +import logging from odoo import models, fields, api from odoo.exceptions import ValidationError, Warning -#_logger = logging.getLogger(__name__) +_logger = logging.getLogger(__name__) class ResPartner(models.Model): _inherit = 'res.partner' @@ -39,29 +39,37 @@ class ResPartner(models.Model): help="Cuándo se realizó la última liquidación de ventas con éste proveedor." ) - @api.onchange('deposit_sale_accept') - def _onchange_deposit_sale_accept(self): - if self.deposit_sale_accept and not self.deposit_sale_location_id: - new_loc = self.env['stock.location'].create({ - 'usage': 'internal', - 'name': self.name, - 'location_id': self.env.ref('stock_picking_deposito.stock_location_deposits_stock').id - }) - self.update({ - 'deposit_sale_location_id': new_loc - }) - - @api.onchange('deposit_buy_accept') - def _onchange_deposit_buy_accept(self): - if self.deposit_buy_accept and not self.deposit_buy_location_id: - new_loc = self.env['stock.location'].create({ - 'usage': 'internal', - 'name': self.name, - 'location_id': self.env.ref('stock_picking_deposito.location_deposit_buy').id - }) - self.update({ - 'deposit_buy_location_id': new_loc - }) + @api.model + def create(self, vals): + if vals.get('deposit_sale_accept', False) == True: + vals['deposit_sale_location_id'] = self.env['stock.location'].create({ + 'usage': 'internal', + 'name': vals.get('name'), + 'location_id': self.env.ref('stock_picking_deposito.stock_location_deposits_stock').id + }).id + if vals.get('deposit_buy_accept', False) == True: + vals['deposit_buy_location_id'] = self.env['stock.location'].create({ + 'usage': 'internal', + 'name': vals.get('name'), + 'location_id': self.env.ref('stock_picking_deposito.location_deposit_buy').id + }).id + return super().create(vals) + + @api.multi + def write(self, vals): + if ( vals.get('deposit_sale_accept', False) == True ) and not self.deposit_sale_location_id: + vals['deposit_sale_location_id'] = self.env['stock.location'].create({ + 'usage': 'internal', + 'name': self.name, + 'location_id': self.env.ref('stock_picking_deposito.stock_location_deposits_stock').id + }).id + if ( vals.get('deposit_buy_accept', False) == True ) and not self.deposit_buy_location_id: + vals['deposit_buy_location_id'] = self.env['stock.location'].create({ + 'usage': 'internal', + 'name': self.name, + 'location_id': self.env.ref('stock_picking_deposito.location_deposit_buy').id + }).id + return super().write(vals) def make_liquidation_buy(self, context = None): invoice_obj = self.env['account.invoice'] diff --git a/stock_picking_deposito/models/stock_picking.py b/stock_picking_deposito/models/stock_picking.py index 49e4ddf..0bcae08 100644 --- a/stock_picking_deposito/models/stock_picking.py +++ b/stock_picking_deposito/models/stock_picking.py @@ -29,14 +29,14 @@ class Picking(models.Model): def change_dest_location(self): if self.picking_type_id.code == 'internal': if not self.partner_id.deposit_sale_accept: - raise ValidationError("Éste cliente no acepta material en depósito, configúralo antes de crear depósitos para él.") + raise ValidationError("Éste cliente no acepta material en depósito, configúralo antes de crear un depósito para él.") return self.update({ 'location_dest_id': self.partner_id.deposit_sale_location_id.id, }) elif self.picking_type_id.code == 'incoming': if not self.partner_id.deposit_buy_accept: - raise ValidationError("Éste proveedor no acepta depósitos, configúralo antes de crear depósitos para él.") + raise ValidationError("Éste proveedor no suministra material en depósito, configúralo antes de crear un depósito para él.") return self.update({ 'location_dest_id': self.partner_id.deposit_buy_location_id.id, diff --git a/stock_picking_deposito/views/view_res_partner.xml b/stock_picking_deposito/views/view_res_partner.xml index 11b7c13..28f34f8 100644 --- a/stock_picking_deposito/views/view_res_partner.xml +++ b/stock_picking_deposito/views/view_res_partner.xml @@ -59,12 +59,12 @@

Depósitos

- + - + @@ -84,7 +84,7 @@ type="action" class="oe_stat_button" icon="fa-calendar" - help="Realiza la factura de ventas para éste cliente." + help="Liquida el depósito de ventas." groups="stock.group_stock_manager" attrs="{'invisible': [('deposit_sale_accept', '!=', True)]}" />