upgrade depositos a v16. Añadida configuración para definir la lista de
precios que se aplica en los depósitos de venta.
This commit is contained in:
parent
5439e39792
commit
a9f5587af5
6 changed files with 34 additions and 43 deletions
|
@ -8,7 +8,12 @@ class Company(models.Model):
|
||||||
_inherit = 'res.company'
|
_inherit = 'res.company'
|
||||||
|
|
||||||
deposit_journal_id = fields.Many2one(
|
deposit_journal_id = fields.Many2one(
|
||||||
comodel_name="account.journal",
|
comodel_name="account.journal",
|
||||||
string="Diario de depósitos",
|
string="Diario de depósitos",
|
||||||
help="El diario donde se crearán las facturas en las liquidaciones de depósitos.",
|
help="El diario donde se crearán las facturas en las liquidaciones de depósitos.",
|
||||||
)
|
)
|
||||||
|
retail_pricelist = fields.Many2one(
|
||||||
|
comodel_name = "product.pricelist",
|
||||||
|
string = "Lista de precios para minoristas en depósito",
|
||||||
|
help = "Ésta tarifa se aplicará cunado se generen liquidaciones de ventas a minoristas",
|
||||||
|
)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Copyright 2021 Criptomart
|
# Copyright 2021-2024 Criptomart
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from odoo import fields, models
|
from odoo import fields, models
|
||||||
|
@ -11,3 +11,7 @@ class ResConfigSettings(models.TransientModel):
|
||||||
related="company_id.deposit_journal_id",
|
related="company_id.deposit_journal_id",
|
||||||
readonly=False,
|
readonly=False,
|
||||||
)
|
)
|
||||||
|
retail_pricelist = fields.Many2one(
|
||||||
|
related="company_id.retail_pricelist",
|
||||||
|
readonly=False,
|
||||||
|
)
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
# Copyright (C) 2021: Criptomart (<https://criptomart.net/>)
|
# Copyright (C) 2021-2024: Criptomart (<https://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
|
|
||||||
|
|
||||||
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__)
|
|
||||||
|
|
||||||
class ResPartner(models.Model):
|
class ResPartner(models.Model):
|
||||||
_inherit = 'res.partner'
|
_inherit = 'res.partner'
|
||||||
|
@ -85,33 +81,32 @@ class ResPartner(models.Model):
|
||||||
new_prod = True
|
new_prod = True
|
||||||
for p in product_list:
|
for p in product_list:
|
||||||
if p[2]['product_id'] == mv.product_id.id:
|
if p[2]['product_id'] == mv.product_id.id:
|
||||||
p[2]['quantity'] += mv.qty_done
|
p[2]['debit'] += mv.qty_done * mv.product_id.standard_price
|
||||||
new_prod = False
|
new_prod = False
|
||||||
break
|
break
|
||||||
if new_prod:
|
if new_prod:
|
||||||
product_list.append([0, False, {
|
product_list.append([0, False, {
|
||||||
'product_id': mv.product_id.id,
|
'product_id': mv.product_id.id,
|
||||||
'quantity': mv.qty_done,
|
'debit': mv.qty_done * mv.product_id.standard_price,
|
||||||
'name': mv.product_id.name,
|
'name': mv.product_id.name,
|
||||||
'price_unit': mv.product_id.lst_price,
|
'price_unit': mv.product_id.lst_price,
|
||||||
'uom_id': mv.product_id.uom_id.id,
|
'tax_ids' : mv.product_id.supplier_taxes_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 = invoice_obj.default_get(invoice_obj._fields.keys())
|
||||||
|
inv_lines = []
|
||||||
invoice_vals.update({
|
invoice_vals.update({
|
||||||
'origin': "Liquidación Compras " + self.deposit_buy_last_liquidation_date.strftime("%d-%m-%Y"),
|
'ref': "Liquidación Compras " + self.deposit_buy_last_liquidation_date.strftime("%d-%m-%Y"),
|
||||||
'type': 'in_invoice',
|
'financial_type': 'payable',
|
||||||
'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,
|
'journal_id': self.env.user.company_id.deposit_journal_id.id,
|
||||||
'partner_id': self.id,
|
'partner_id': self.id,
|
||||||
'invoice_line_ids': product_list,
|
'invoice_line_ids': product_list,
|
||||||
'company_id': self.company_id.id,
|
'company_id': self.company_id.id,
|
||||||
})
|
})
|
||||||
invoice = invoice_obj.create(invoice_vals)
|
invoice = invoice_obj.create(invoice_vals)
|
||||||
views = [(self.env.ref('account.invoice_form').id, 'form')]
|
self.deposit_buy_last_liquidation_date = fields.datetime.now()
|
||||||
|
views = [(self.env.ref('account.view_move_form').id, 'form')]
|
||||||
return {
|
return {
|
||||||
'type': 'ir.actions.act_window',
|
'type': 'ir.actions.act_window',
|
||||||
'res_model': 'account.move',
|
'res_model': 'account.move',
|
||||||
|
@ -139,8 +134,6 @@ class ResPartner(models.Model):
|
||||||
'product_id': mv.product_id.id,
|
'product_id': mv.product_id.id,
|
||||||
'product_uom_qty': mv.quantity,
|
'product_uom_qty': mv.quantity,
|
||||||
'name': mv.product_id.name,
|
'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):
|
||||||
|
@ -150,9 +143,10 @@ class ResPartner(models.Model):
|
||||||
'partner_id': self.id,
|
'partner_id': self.id,
|
||||||
'origin': "Liquidación Ventas " + self.deposit_sale_last_liquidation_date.strftime("%d-%m-%Y"),
|
'origin': "Liquidación Ventas " + self.deposit_sale_last_liquidation_date.strftime("%d-%m-%Y"),
|
||||||
'date_order': self.deposit_sale_last_liquidation_date.strftime("%Y-%m-%d %H:%M:%S"),
|
'date_order': self.deposit_sale_last_liquidation_date.strftime("%Y-%m-%d %H:%M:%S"),
|
||||||
#'journal_id': self.env.user.company_id.deposit_journal_id.id,
|
|
||||||
'order_line': product_list,
|
'order_line': product_list,
|
||||||
'warehouse_id': self.env.ref('stock_picking_deposito.wh_deposits').id
|
'warehouse_id': self.env.ref('stock_picking_deposito.wh_deposits').id,
|
||||||
|
'pricelist_id': self.env.user.company_id.retail_pricelist.id,
|
||||||
|
|
||||||
})
|
})
|
||||||
sale_order = self.env['sale.order'].sudo().create(so_vals)
|
sale_order = self.env['sale.order'].sudo().create(so_vals)
|
||||||
views = [(self.env.ref('sale.view_order_form').id, 'form')]
|
views = [(self.env.ref('sale.view_order_form').id, 'form')]
|
||||||
|
@ -170,4 +164,3 @@ class ResPartner(models.Model):
|
||||||
else:
|
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)
|
raise ValidationError(msg)
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
# Copyright 2021 Criptomart
|
# Copyright 2021 Criptomart
|
||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
|
||||||
|
|
||||||
#import logging
|
import logging
|
||||||
|
|
||||||
from odoo import api, models, fields
|
from odoo import api, models, fields
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
#_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class PickingType(models.Model):
|
class PickingType(models.Model):
|
||||||
_inherit = 'stock.picking.type'
|
_inherit = 'stock.picking.type'
|
||||||
|
@ -14,7 +14,7 @@ class PickingType(models.Model):
|
||||||
is_deposit = fields.Boolean(
|
is_deposit = fields.Boolean(
|
||||||
string='Depósito',
|
string='Depósito',
|
||||||
help='Éste albarán es un depósito, no es una venta final.',
|
help='Éste albarán es un depósito, no es una venta final.',
|
||||||
default= False,
|
default= False,
|
||||||
)
|
)
|
||||||
|
|
||||||
class Picking(models.Model):
|
class Picking(models.Model):
|
||||||
|
@ -22,20 +22,10 @@ class Picking(models.Model):
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def create(self, vals):
|
def create(self, vals):
|
||||||
if vals.get("partner_id") and vals.get("location_id") == self.env.ref("stock_picking_deposito.stock_location_deposits_stock").id:
|
pick = super().create(vals)
|
||||||
partner = self.env['res.partner'].browse(vals.get("partner_id"))
|
if pick.picking_type_id.is_deposit:
|
||||||
vals['location_id'] = partner.deposit_sale_location_id.id
|
pick.change_dest_location()
|
||||||
return super().create(vals)
|
return pick
|
||||||
|
|
||||||
@api.onchange('picking_type_id','partner_id')
|
|
||||||
def onchange_picking_type(self):
|
|
||||||
super(Picking, self).onchange_picking_type()
|
|
||||||
if self.picking_type_id.is_deposit and self.partner_id:
|
|
||||||
self.change_dest_location()
|
|
||||||
if self.partner_id and self.location_id == self.env.ref("stock_picking_deposito.stock_location_deposits_stock"):
|
|
||||||
self.update({
|
|
||||||
'location_id': self.partner_id.deposit_sale_location_id.id,
|
|
||||||
})
|
|
||||||
|
|
||||||
def change_dest_location(self):
|
def change_dest_location(self):
|
||||||
if self.picking_type_id.code == 'internal':
|
if self.picking_type_id.code == 'internal':
|
||||||
|
@ -52,4 +42,3 @@ class Picking(models.Model):
|
||||||
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,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<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.deposit</field>
|
<field name="name">res.config.settings.view.form.inherit.product.deposit</field>
|
||||||
<field name="model">res.config.settings</field>
|
<field name="model">res.config.settings</field>
|
||||||
|
@ -16,11 +15,14 @@
|
||||||
<label for="deposit_journal_id" />
|
<label for="deposit_journal_id" />
|
||||||
<field name="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 class="text-muted">El diario donde se crearán las facturas de liquidaciones de depósitos.</div>
|
||||||
|
<br/>
|
||||||
|
<label for="retail_pricelist" />
|
||||||
|
<field name="retail_pricelist" />
|
||||||
|
<div class="text-muted">List de precios que aplica a las facturas de ventas generadas en liquidaciones de depósitos a minoristas.</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<odoo>
|
<odoo>
|
||||||
|
|
||||||
<record id="view_picking_type_form_inherit" model="ir.ui.view">
|
<record id="view_picking_type_form_inherit" model="ir.ui.view">
|
||||||
<field name="name">Operation Types inherit</field>
|
<field name="name">Operation Types inherit</field>
|
||||||
<field name="inherit_id" ref="stock.view_picking_type_form" />
|
<field name="inherit_id" ref="stock.view_picking_type_form" />
|
||||||
|
@ -10,5 +9,4 @@
|
||||||
</field>
|
</field>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
Loading…
Add table
Reference in a new issue