Movida la creación de location del partner al create y al write de res.artner en vez de en el onchange.

readonly para los campos location en la ficha del partner
This commit is contained in:
santiky 2021-09-12 17:31:13 +02:00
parent 0ab76a67a1
commit 8ae2c3a1b8
Signed by: snt
GPG key ID: A9FD34930EADBE71
3 changed files with 38 additions and 30 deletions

View file

@ -2,12 +2,12 @@
# @author: Criptomart (<tech@criptomart.net>)
# 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']