From 8ae2c3a1b8342c6f6282556a17d38a21b616c458 Mon Sep 17 00:00:00 2001 From: santiky Date: Sun, 12 Sep 2021 17:31:13 +0200 Subject: [PATCH] =?UTF-8?q?Movida=20la=20creaci=C3=B3n=20de=20location=20d?= =?UTF-8?q?el=20partner=20al=20create=20y=20al=20write=20de=20res.artner?= =?UTF-8?q?=20en=20vez=20de=20en=20el=20onchange.=20readonly=20para=20los?= =?UTF-8?q?=20campos=20location=20en=20la=20ficha=20del=20partner?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stock_picking_deposito/models/res_partner.py | 58 +++++++++++-------- .../models/stock_picking.py | 4 +- .../views/view_res_partner.xml | 6 +- 3 files changed, 38 insertions(+), 30 deletions(-) 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)]}" />