[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,7 +1,5 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- Copyright 2018 Eficent Business and IT Consulting Services S.L.
|
|
||||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
|
||||||
<odoo>
|
<odoo>
|
||||||
|
|
||||||
<record id="res_config_settings_view_form" model="ir.ui.view">
|
<record id="res_config_settings_view_form" model="ir.ui.view">
|
||||||
<field name="name">res.config.settings.view.form.inherit.product</field>
|
<field name="name">res.config.settings.view.form.inherit.product</field>
|
||||||
<field name="model">res.config.settings</field>
|
<field name="model">res.config.settings</field>
|
||||||
|
@ -24,4 +22,5 @@
|
||||||
</div>
|
</div>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
|
||||||
{
|
{
|
||||||
"name": "Stock Picking Depósito",
|
"name": "Stock Picking Depósito",
|
||||||
"summary": "Permite la gestión de depósitos en el almacén.",
|
"summary": "Permite la gestión de depósitos en el almacén y su facturación.",
|
||||||
"version": "12.0.1.0.1",
|
"version": "12.0.1.0.1",
|
||||||
"development_status": "Alpha",
|
"development_status": "Alpha",
|
||||||
"category": "Warehouse Management",
|
"category": "Warehouse Management",
|
||||||
|
@ -13,9 +13,11 @@
|
||||||
"installable": True,
|
"installable": True,
|
||||||
"depends": [
|
"depends": [
|
||||||
"stock",
|
"stock",
|
||||||
|
"account",
|
||||||
],
|
],
|
||||||
"data": [
|
"data": [
|
||||||
"views/view_res_partner.xml",
|
"views/view_res_partner.xml",
|
||||||
"data/data.xml",
|
"data/data.xml",
|
||||||
|
"views/res_config_settings_views.xml",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
from . import stock_picking
|
from . import stock_picking
|
||||||
from . import res_partner
|
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>)
|
# @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 collections import Counter
|
|
||||||
|
|
||||||
from odoo import models, fields, api
|
from odoo import models, fields, api
|
||||||
|
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'
|
||||||
|
@ -31,7 +30,7 @@ class ResPartner(models.Model):
|
||||||
string='Ubicación de depósito de compras',
|
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."
|
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',
|
string='Fecha de la última liquidación de compras',
|
||||||
help="Cuándo se realizó la última liquidación de compras con éste proveedor."
|
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
|
'deposit_buy_location_id': new_loc
|
||||||
})
|
})
|
||||||
|
|
||||||
def make_liquidation_buy(self):
|
def make_liquidation_buy(self, context = None):
|
||||||
_logger.warning("make_liquidation : %s" %self)
|
invoice_obj = self.env['account.invoice']
|
||||||
search_vals = [
|
search_vals = [
|
||||||
('location_id', '=', self.deposit_buy_location_id.id),
|
('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_customers').id),
|
||||||
]
|
]
|
||||||
if self.deposit_buy_last_liquidation_date:
|
if self.deposit_buy_last_liquidation_date:
|
||||||
search_vals += ('date', '>', self.deposit_buy_last_liquidation_date)
|
search_vals.append(('date', '>', self.deposit_buy_last_liquidation_date.strftime("%Y-%m-%d %H:%M:%S")))
|
||||||
_logger.warning("search_vals : %s" %search_vals)
|
|
||||||
move_lines = self.env['stock.move.line'].search(search_vals)
|
move_lines = self.env['stock.move.line'].search(search_vals)
|
||||||
product_list = Counter()
|
product_list = []
|
||||||
for mv in move_lines:
|
for mv in move_lines:
|
||||||
product_list += {'id': mv.product_id.id, 'qty': mv.qty_done}
|
new_prod = True
|
||||||
_logger.warning("product_list : %s" %product_list)
|
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)
|
||||||
|
|
||||||
|
|
26
stock_picking_deposito/views/res_config_settings_views.xml
Normal file
26
stock_picking_deposito/views/res_config_settings_views.xml
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<record id="res_config_settings_view_form" model="ir.ui.view">
|
||||||
|
<field name="name">res.config.settings.view.form.inherit.product.deposit</field>
|
||||||
|
<field name="model">res.config.settings</field>
|
||||||
|
<field name="inherit_id" ref="product.res_config_settings_view_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<div id="invoicing_settings" position="after">
|
||||||
|
<h2>Deposit Settings</h2>
|
||||||
|
<div id="deposit_settings" class="row mt16 o_settings_container">
|
||||||
|
<div class="col-12 col-lg-6 o_setting_box">
|
||||||
|
<div class="o_setting_left_pane">
|
||||||
|
</div>
|
||||||
|
<div class="o_setting_right_pane">
|
||||||
|
<label for="deposit_journal_id" />
|
||||||
|
<field name="deposit_journal_id" />
|
||||||
|
<div class="text-muted">El diario donde se crearán las facturas de liquidaciones de depósitos.</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
|
@ -1,30 +1,45 @@
|
||||||
<odoo>
|
<odoo>
|
||||||
<data>
|
<data>
|
||||||
|
|
||||||
<record model="ir.actions.server" id="action_res_partner_liquidacion_buy">
|
<record model="ir.actions.server" id="action_res_partner_liquidacion_buy">
|
||||||
<field name="name">Liquidación Depósito Compras</field>
|
<field name="name">Liquidación Depósito Compras</field>
|
||||||
<field name="condition">True</field>
|
<field name="condition">True</field>
|
||||||
<field name="type">ir.actions.server</field>
|
<field name="type">ir.actions.server</field>
|
||||||
<field name="model_id" ref="base.model_res_partner" />
|
<field name="model_id" ref="base.model_res_partner" />
|
||||||
<field name="state">code</field>
|
<field name="state">code</field>
|
||||||
<field name="code">record.make_liquidation_buy()</field>
|
<field name="code">action =record.make_liquidation_buy()</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
<record id="action_open_liquidacion_buy" model="ir.actions.act_window">
|
||||||
|
<field name="name">Abre Liquidación</field>
|
||||||
|
<field name="res_model">account.invoice</field>
|
||||||
|
<field name="view_type">form</field>
|
||||||
|
<field name="view_mode">tree,form</field>
|
||||||
|
<field name="view_id" ref="account.invoice_supplier_form"/>
|
||||||
|
<field name="target">new</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record model="ir.ui.view" id="view_open_liquidation_buy">
|
||||||
|
<field name="name">view_open_liquidation_buy_form</field>
|
||||||
|
<field name="model">account.invoice</field>
|
||||||
|
<field name="groups_id"></field>
|
||||||
|
<field name="type">form</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
<record id="view_partner_form" model="ir.ui.view">
|
<record id="view_partner_form" model="ir.ui.view">
|
||||||
<field name="model">res.partner</field>
|
<field name="model">res.partner</field>
|
||||||
<field name="inherit_id" ref="base.view_partner_form"/>
|
<field name="inherit_id" ref="base.view_partner_form"/>
|
||||||
<field name="priority">200</field>
|
<field name="priority">200</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
|
|
||||||
<field name="vat" position="after">
|
<field name="vat" position="after">
|
||||||
<group>
|
<group>
|
||||||
<field name="deposit_sale_accept"/>
|
<field name="deposit_sale_accept"/>
|
||||||
<field name="deposit_sale_location_id" />
|
<field name="deposit_sale_location_id" />
|
||||||
<field name="deposit_buy_accept"/>
|
<field name="deposit_buy_accept"/>
|
||||||
<field name="deposit_buy_location_id" />
|
<field name="deposit_buy_location_id" />
|
||||||
|
<field name="deposit_buy_last_liquidation_date" readonly="1" />
|
||||||
</group>
|
</group>
|
||||||
</field>
|
</field>
|
||||||
|
|
||||||
<div name="button_box" position="inside">
|
<div name="button_box" position="inside">
|
||||||
<button name="%(stock_picking_deposito.action_res_partner_liquidacion_buy)d"
|
<button name="%(stock_picking_deposito.action_res_partner_liquidacion_buy)d"
|
||||||
string="Liquida Compras"
|
string="Liquida Compras"
|
||||||
|
@ -34,35 +49,10 @@
|
||||||
help="Realiza el informe de liquidación para éste proveedor."
|
help="Realiza el informe de liquidación para éste proveedor."
|
||||||
groups="stock.group_stock_manager"
|
groups="stock.group_stock_manager"
|
||||||
attrs="{'invisible': [('deposit_buy_accept', '!=', True)]}"
|
attrs="{'invisible': [('deposit_buy_accept', '!=', True)]}"
|
||||||
>
|
/>
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
<!--
|
|
||||||
<record model="ir.actions.act_window" id="action_res_partner_liquidacion_buy">
|
|
||||||
<field name="name">Informe de liquidación</field>
|
|
||||||
<field name="type">ir.actions.act_window</field>
|
|
||||||
<field name="res_model">stock.picking</field>
|
|
||||||
<field name="view_type">tree</field>
|
|
||||||
<field name="view_mode">tree</field>
|
|
||||||
<field name="context">{'default_location_dest_id': stock.stock_location_customers, 'default_partner_id': active_id}</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<record id="view_res_partner_liquidacion_tree" model="ir.ui.view">
|
|
||||||
<field name="name">res.partner.liquidacion.list</field>
|
|
||||||
<field name="model">stock.picking</field>
|
|
||||||
<field name="arch" type="xml">
|
|
||||||
<tree create='false' edit='false' delete='false'>
|
|
||||||
<field name="name"/>
|
|
||||||
<field name="partner_id"/>
|
|
||||||
<field name="category_id"/>
|
|
||||||
<field name="owned_share" sum="Total Owned Shares"/>
|
|
||||||
</tree>
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
-->
|
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
Loading…
Add table
Reference in a new issue