Hereda la validación de cuentas bancarias al crear la factura y pone la cuenta a False en vez de elevar un error.
En la base de datos de la ddt da un error creando una fatura de compra, asigna partner_bank_id a la cuenta de la compañia en vez de la cuenta del proveedor.
This commit is contained in:
parent
9bd253a931
commit
a1cfaeba74
3 changed files with 43 additions and 18 deletions
|
@ -2,3 +2,4 @@ from . import stock_picking
|
|||
from . import res_partner
|
||||
from . import res_config_settings
|
||||
from . import res_company
|
||||
from . import account_invoice
|
||||
|
|
24
stock_picking_deposito/models/account_invoice.py
Normal file
24
stock_picking_deposito/models/account_invoice.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Copyright (C) 2021: Criptomart (<https://criptomart.net/>)
|
||||
# @author: Criptomart (<tech@criptomart.net>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
import logging
|
||||
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import ValidationError, Warning
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
class AccountInvoice(models.Model):
|
||||
_inherit = 'account.invoice'
|
||||
|
||||
@api.constrains('partner_id', 'partner_bank_id')
|
||||
def validate_partner_bank_id(self):
|
||||
for record in self:
|
||||
if record.partner_bank_id:
|
||||
if record.type in ('in_invoice', 'out_refund') and record.partner_bank_id.partner_id != record.partner_id.commercial_partner_id:
|
||||
_logger.warning(_("Commercial partner and vendor account owners must be identical."))
|
||||
record.partner_bank_id = False
|
||||
elif record.type in ('out_invoice', 'in_refund') and not record.company_id in record.partner_bank_id.partner_id.ref_company_ids:
|
||||
raise ValidationError(_("The account selected for payment does not belong to the same company as this invoice."))
|
||||
|
|
@ -21,23 +21,23 @@ class ResPartner(models.Model):
|
|||
help='Éste proveedor nos deja material a depósito.',
|
||||
)
|
||||
deposit_sale_location_id = fields.Many2one(
|
||||
comodel_name='stock.location',
|
||||
comodel_name='stock.location',
|
||||
string='Ubicación de depósito de ventas',
|
||||
help="Ubicación usada para gestionar el depósito que dejamos a éste proveedor."
|
||||
)
|
||||
deposit_buy_location_id = fields.Many2one(
|
||||
comodel_name='stock.location',
|
||||
comodel_name='stock.location',
|
||||
string='Ubicación de depósito de compras',
|
||||
help="Ubicación usada para gestionar el material que éste proveedor nos deja en depósito."
|
||||
)
|
||||
deposit_buy_last_liquidation_date = fields.Datetime(
|
||||
string='Fecha última liquidación compras',
|
||||
help="Cuándo se realizó la última liquidación de compras con éste proveedor."
|
||||
)
|
||||
)
|
||||
deposit_sale_last_liquidation_date = fields.Datetime(
|
||||
string='Fecha última liquidación ventas',
|
||||
help="Cuándo se realizó la última liquidación de ventas con éste proveedor."
|
||||
)
|
||||
)
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
|
@ -54,7 +54,7 @@ class ResPartner(models.Model):
|
|||
'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:
|
||||
|
@ -72,12 +72,12 @@ class ResPartner(models.Model):
|
|||
return super().write(vals)
|
||||
|
||||
def make_liquidation_buy(self, context = None):
|
||||
invoice_obj = self.env['account.invoice']
|
||||
invoice_obj = self.env['account.invoice']
|
||||
search_vals = [
|
||||
('location_id', '=', self.deposit_buy_location_id.id),'|',
|
||||
('location_dest_id', '=', self.env.ref('stock.stock_location_customers').id),
|
||||
('location_dest_id', '=', self.env.ref('stock.stock_location_stock').id),
|
||||
]
|
||||
]
|
||||
if self.deposit_buy_last_liquidation_date:
|
||||
search_vals.append(('date', '>', self.deposit_buy_last_liquidation_date.strftime("%Y-%m-%d %H:%M:%S")))
|
||||
move_lines = self.env['stock.move.line'].search(search_vals)
|
||||
|
@ -91,15 +91,15 @@ class ResPartner(models.Model):
|
|||
break
|
||||
if new_prod:
|
||||
product_list.append([0, False, {
|
||||
'product_id': mv.product_id.id,
|
||||
'product_id': mv.product_id.id,
|
||||
'quantity': mv.qty_done,
|
||||
'name': mv.product_id.name,
|
||||
'price_unit': mv.product_id.lst_price,
|
||||
'uom_id': mv.product_id.uom_id.id,
|
||||
'account_id': self.env['account.account'].search([('user_type_id', '=', self.env.ref('account.data_account_type_expenses').id)], limit=1).id
|
||||
'account_id': self.env['account.account'].search([('user_type_id', '=', self.env.ref('account.data_account_type_expenses').id)], limit=1).id
|
||||
}
|
||||
])
|
||||
if len(product_list):
|
||||
if len(product_list):
|
||||
self.deposit_buy_last_liquidation_date = fields.datetime.now()
|
||||
invoice_vals = invoice_obj.default_get(invoice_obj._fields.keys())
|
||||
invoice_vals.update({
|
||||
|
@ -107,9 +107,9 @@ class ResPartner(models.Model):
|
|||
'type': 'in_invoice',
|
||||
'date_invoice': self.deposit_buy_last_liquidation_date.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
'journal_id': self.env.user.company_id.deposit_journal_id.id,
|
||||
'account_id': self.env['account.account'].search([('user_type_id', '=', self.env.ref('account.data_account_type_receivable').id)], limit=1).id,
|
||||
'partner_id': self.id,
|
||||
'invoice_line_ids': product_list,
|
||||
'company_id': self.company_id.id,
|
||||
})
|
||||
invoice = self.env['account.invoice'].create(invoice_vals)
|
||||
views = [(self.env.ref('account.invoice_form').id, 'form')]
|
||||
|
@ -122,28 +122,28 @@ class ResPartner(models.Model):
|
|||
}
|
||||
else:
|
||||
msg= "No se ha vendido ningún producto en depósito de éste provedor desde la última liquidación.\n\n"
|
||||
if self.deposit_buy_last_liquidation_date:
|
||||
if self.deposit_buy_last_liquidation_date:
|
||||
msg += "Fecha última liquidación de compras : %s" %self.deposit_buy_last_liquidation_date.strftime("%d-%m-%Y, %H:%M:%S")
|
||||
else:
|
||||
msg += "Todavía no se ha realizado ninguna liquidación de compras a éste proveedor."
|
||||
msg += "Todavía no se ha realizado ninguna liquidación de compras a éste proveedor."
|
||||
raise ValidationError(msg)
|
||||
|
||||
def make_liquidation_sale(self, context = None):
|
||||
self.deposit_sale_location_id
|
||||
sale_order_obj = self.env['sale.order']
|
||||
sale_order_obj = self.env['sale.order']
|
||||
search_vals = [('location_id', '=', self.deposit_sale_location_id.id)]
|
||||
stock_lines = self.env['stock.quant'].search(search_vals)
|
||||
product_list = []
|
||||
for mv in stock_lines:
|
||||
product_list.append([0, False, {
|
||||
'product_id': mv.product_id.id,
|
||||
'product_id': mv.product_id.id,
|
||||
'product_uom_qty': mv.quantity,
|
||||
'name': mv.product_id.name,
|
||||
'price_unit': mv.product_id.lst_price,
|
||||
'product_uom': mv.product_id.uom_id.id,
|
||||
}
|
||||
])
|
||||
if len(product_list):
|
||||
if len(product_list):
|
||||
self.deposit_sale_last_liquidation_date = fields.datetime.now()
|
||||
so_vals = sale_order_obj.default_get(sale_order_obj._fields.keys())
|
||||
so_vals.update({
|
||||
|
@ -165,9 +165,9 @@ class ResPartner(models.Model):
|
|||
}
|
||||
else:
|
||||
msg= "No hay ningún producto enviado en depósito a éste cliente desde la última liquidación de ventas.\n\n"
|
||||
if self.deposit_sale_last_liquidation_date:
|
||||
if self.deposit_sale_last_liquidation_date:
|
||||
msg += "Fecha última liquidación de ventas: %s" %self.deposit_buy_last_liquidation_date.strftime("%d-%m-%Y, %H:%M:%S")
|
||||
else:
|
||||
msg += "Todavía no se ha realizado ninguna liquidación de ventas a éste proveedor."
|
||||
msg += "Todavía no se ha realizado ninguna liquidación de ventas a éste proveedor."
|
||||
raise ValidationError(msg)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue