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>)
|
# @author: Criptomart (<tech@criptomart.net>)
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# 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 import models, fields, api
|
||||||
from odoo.exceptions import ValidationError, Warning
|
from odoo.exceptions import ValidationError, Warning
|
||||||
|
|
||||||
#_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class ResPartner(models.Model):
|
class ResPartner(models.Model):
|
||||||
_inherit = 'res.partner'
|
_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."
|
help="Cuándo se realizó la última liquidación de ventas con éste proveedor."
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.onchange('deposit_sale_accept')
|
@api.model
|
||||||
def _onchange_deposit_sale_accept(self):
|
def create(self, vals):
|
||||||
if self.deposit_sale_accept and not self.deposit_sale_location_id:
|
if vals.get('deposit_sale_accept', False) == True:
|
||||||
new_loc = self.env['stock.location'].create({
|
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',
|
'usage': 'internal',
|
||||||
'name': self.name,
|
'name': self.name,
|
||||||
'location_id': self.env.ref('stock_picking_deposito.stock_location_deposits_stock').id
|
'location_id': self.env.ref('stock_picking_deposito.stock_location_deposits_stock').id
|
||||||
})
|
}).id
|
||||||
self.update({
|
if ( vals.get('deposit_buy_accept', False) == True ) and not self.deposit_buy_location_id:
|
||||||
'deposit_sale_location_id': new_loc
|
vals['deposit_buy_location_id'] = self.env['stock.location'].create({
|
||||||
})
|
|
||||||
|
|
||||||
@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',
|
'usage': 'internal',
|
||||||
'name': self.name,
|
'name': self.name,
|
||||||
'location_id': self.env.ref('stock_picking_deposito.location_deposit_buy').id
|
'location_id': self.env.ref('stock_picking_deposito.location_deposit_buy').id
|
||||||
})
|
}).id
|
||||||
self.update({
|
return super().write(vals)
|
||||||
'deposit_buy_location_id': new_loc
|
|
||||||
})
|
|
||||||
|
|
||||||
def make_liquidation_buy(self, context = None):
|
def make_liquidation_buy(self, context = None):
|
||||||
invoice_obj = self.env['account.invoice']
|
invoice_obj = self.env['account.invoice']
|
||||||
|
|
|
@ -29,14 +29,14 @@ class Picking(models.Model):
|
||||||
def change_dest_location(self):
|
def change_dest_location(self):
|
||||||
if self.picking_type_id.code == 'internal':
|
if self.picking_type_id.code == 'internal':
|
||||||
if not self.partner_id.deposit_sale_accept:
|
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
|
return
|
||||||
self.update({
|
self.update({
|
||||||
'location_dest_id': self.partner_id.deposit_sale_location_id.id,
|
'location_dest_id': self.partner_id.deposit_sale_location_id.id,
|
||||||
})
|
})
|
||||||
elif self.picking_type_id.code == 'incoming':
|
elif self.picking_type_id.code == 'incoming':
|
||||||
if not self.partner_id.deposit_buy_accept:
|
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
|
return
|
||||||
self.update({
|
self.update({
|
||||||
'location_dest_id': self.partner_id.deposit_buy_location_id.id,
|
'location_dest_id': self.partner_id.deposit_buy_location_id.id,
|
||||||
|
|
|
@ -59,12 +59,12 @@
|
||||||
<div clas="o_horizontal_separator"><h2>Depósitos</h2></div>
|
<div clas="o_horizontal_separator"><h2>Depósitos</h2></div>
|
||||||
<group class="o_group o_inner_group o_group_col_6">
|
<group class="o_group o_inner_group o_group_col_6">
|
||||||
<field name="deposit_sale_accept"/>
|
<field name="deposit_sale_accept"/>
|
||||||
<field name="deposit_sale_location_id" />
|
<field name="deposit_sale_location_id" readonly="1" />
|
||||||
<field name="deposit_sale_last_liquidation_date" readonly="1" />
|
<field name="deposit_sale_last_liquidation_date" readonly="1" />
|
||||||
</group>
|
</group>
|
||||||
<group class="o_group o_inner_group o_group_col_6">
|
<group class="o_group o_inner_group o_group_col_6">
|
||||||
<field name="deposit_buy_accept"/>
|
<field name="deposit_buy_accept"/>
|
||||||
<field name="deposit_buy_location_id" />
|
<field name="deposit_buy_location_id" readonly="1" />
|
||||||
<field name="deposit_buy_last_liquidation_date" readonly="1" />
|
<field name="deposit_buy_last_liquidation_date" readonly="1" />
|
||||||
</group>
|
</group>
|
||||||
</page>
|
</page>
|
||||||
|
@ -84,7 +84,7 @@
|
||||||
type="action"
|
type="action"
|
||||||
class="oe_stat_button"
|
class="oe_stat_button"
|
||||||
icon="fa-calendar"
|
icon="fa-calendar"
|
||||||
help="Realiza la factura de ventas para éste cliente."
|
help="Liquida el depósito de ventas."
|
||||||
groups="stock.group_stock_manager"
|
groups="stock.group_stock_manager"
|
||||||
attrs="{'invisible': [('deposit_sale_accept', '!=', True)]}"
|
attrs="{'invisible': [('deposit_sale_accept', '!=', True)]}"
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Add table
Reference in a new issue