[wip] Funcionando la liquidación de depósitos de compras
- Hay un nuevo botón en res.partner que dispara la acción. - La acción comprueba move.stock.line con origen la ubicación del depósito del provvedor y destino clientes después de la última liquidación. - Nuevo campo en res.partner para guardar la fecha de la útlima liquidación. - La acción redirige a la factura en borrador recién creada. - Nueva configuración en Facturación para definir el journal donde van las facturas de depósito
This commit is contained in:
parent
fbda713b52
commit
74c1c6d641
8 changed files with 134 additions and 48 deletions
|
@ -1,2 +1,4 @@
|
|||
from . import stock_picking
|
||||
from . import res_partner
|
||||
from . import res_config_settings
|
||||
from . import res_company
|
||||
|
|
14
stock_picking_deposito/models/res_company.py
Normal file
14
stock_picking_deposito/models/res_company.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
# Copyright 2021 Criptomart
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class Company(models.Model):
|
||||
_inherit = 'res.company'
|
||||
|
||||
deposit_journal_id = fields.Many2one(
|
||||
comodel_name="account.journal",
|
||||
string="Diario de depósitos",
|
||||
help="El diario donde se crearán las facturas en las liquidaciones de depósitos.",
|
||||
)
|
13
stock_picking_deposito/models/res_config_settings.py
Normal file
13
stock_picking_deposito/models/res_config_settings.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Copyright 2021 Criptomart
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
_inherit = 'res.config.settings'
|
||||
|
||||
deposit_journal_id = fields.Many2one(
|
||||
related="company_id.deposit_journal_id",
|
||||
readonly=False,
|
||||
)
|
|
@ -2,13 +2,12 @@
|
|||
# @author: Criptomart (<tech@criptomart.net>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
import logging
|
||||
|
||||
from collections import Counter
|
||||
#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'
|
||||
|
@ -31,7 +30,7 @@ class ResPartner(models.Model):
|
|||
string='Ubicación de depósito de compras',
|
||||
help="La ubicación que se usará para gestionar el material que éste proveedor nos deja en depósito."
|
||||
)
|
||||
deposit_buy_last_liquidation_date = fields.Date(
|
||||
deposit_buy_last_liquidation_date = fields.Datetime(
|
||||
string='Fecha de la última liquidación de compras',
|
||||
help="Cuándo se realizó la última liquidación de compras con éste proveedor."
|
||||
)
|
||||
|
@ -60,18 +59,59 @@ class ResPartner(models.Model):
|
|||
'deposit_buy_location_id': new_loc
|
||||
})
|
||||
|
||||
def make_liquidation_buy(self):
|
||||
_logger.warning("make_liquidation : %s" %self)
|
||||
def make_liquidation_buy(self, context = None):
|
||||
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),
|
||||
]
|
||||
if self.deposit_buy_last_liquidation_date:
|
||||
search_vals += ('date', '>', self.deposit_buy_last_liquidation_date)
|
||||
_logger.warning("search_vals : %s" %search_vals)
|
||||
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)
|
||||
product_list = Counter()
|
||||
product_list = []
|
||||
for mv in move_lines:
|
||||
product_list += {'id': mv.product_id.id, 'qty': mv.qty_done}
|
||||
_logger.warning("product_list : %s" %product_list)
|
||||
new_prod = True
|
||||
for p in product_list:
|
||||
if p[2]['product_id'] == mv.product_id.id:
|
||||
p[2]['quantity'] += mv.qty_done
|
||||
new_prod = False
|
||||
break
|
||||
if new_prod:
|
||||
product_list.append([0, False, {
|
||||
'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
|
||||
}
|
||||
])
|
||||
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({
|
||||
'origin': "Liquidación " + self.deposit_buy_last_liquidation_date.strftime("%d-%m-%Y"),
|
||||
'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,
|
||||
})
|
||||
invoice = self.env['account.invoice'].create(invoice_vals)
|
||||
views = [(self.env.ref('account.invoice_form').id, 'form')]
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'account.invoice',
|
||||
'res_id': invoice.id,
|
||||
'target': 'current',
|
||||
'views': views,
|
||||
}
|
||||
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:
|
||||
msg += "Fecha última liquidación : %s" %self.deposit_buy_last_liquidation_date.strftime("%d-%m-%Y, %H:%M:%S")
|
||||
else:
|
||||
msg += "No se ha realizado ninguna liquidación a éste proveedor."
|
||||
raise ValidationError(msg)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue