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:
parent
0ab76a67a1
commit
8ae2c3a1b8
3 changed files with 38 additions and 30 deletions
|
@ -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']
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue