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
							
								
									bee00e0867
								
							
						
					
					
						commit
						ca3ff032a2
					
				
					 6 changed files with 34 additions and 43 deletions
				
			
		| 
						 | 
				
			
			@ -12,3 +12,8 @@ class Company(models.Model):
 | 
			
		|||
        string="Diario 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).
 | 
			
		||||
 | 
			
		||||
from odoo import fields, models
 | 
			
		||||
| 
						 | 
				
			
			@ -11,3 +11,7 @@ class ResConfigSettings(models.TransientModel):
 | 
			
		|||
        related="company_id.deposit_journal_id",
 | 
			
		||||
        readonly=False,
 | 
			
		||||
    )
 | 
			
		||||
    retail_pricelist = fields.Many2one(
 | 
			
		||||
        related="company_id.retail_pricelist",
 | 
			
		||||
        readonly=False,
 | 
			
		||||
    )
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,13 +1,9 @@
 | 
			
		|||
# Copyright (C) 2021: Criptomart (<https://criptomart.net/>)
 | 
			
		||||
# @author: Criptomart (<tech@criptomart.net>)
 | 
			
		||||
# Copyright (C) 2021-2024: Criptomart (<https://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 ResPartner(models.Model):
 | 
			
		||||
     _inherit = 'res.partner'
 | 
			
		||||
| 
						 | 
				
			
			@ -85,33 +81,32 @@ class ResPartner(models.Model):
 | 
			
		|||
          new_prod = True
 | 
			
		||||
          for p in product_list:
 | 
			
		||||
              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
 | 
			
		||||
                  break
 | 
			
		||||
          if new_prod:
 | 
			
		||||
              product_list.append([0, False, {
 | 
			
		||||
                  'product_id': mv.product_id.id,
 | 
			
		||||
                  'quantity': mv.qty_done,
 | 
			
		||||
                  'debit': mv.qty_done * mv.product_id.standard_price,
 | 
			
		||||
                  '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
 | 
			
		||||
                  'tax_ids' : mv.product_id.supplier_taxes_id,
 | 
			
		||||
                }
 | 
			
		||||
              ])
 | 
			
		||||
        if len(product_list):
 | 
			
		||||
            self.deposit_buy_last_liquidation_date = fields.datetime.now()
 | 
			
		||||
            invoice_vals = invoice_obj.default_get(invoice_obj._fields.keys())
 | 
			
		||||
            inv_lines = []
 | 
			
		||||
            invoice_vals.update({
 | 
			
		||||
                'origin': "Liquidación Compras " + 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"),
 | 
			
		||||
                'ref': "Liquidación Compras " + self.deposit_buy_last_liquidation_date.strftime("%d-%m-%Y"),
 | 
			
		||||
                'financial_type': 'payable',
 | 
			
		||||
                'journal_id': self.env.user.company_id.deposit_journal_id.id,
 | 
			
		||||
                'partner_id': self.id,
 | 
			
		||||
                'invoice_line_ids': product_list,
 | 
			
		||||
                'company_id': self.company_id.id,
 | 
			
		||||
            })
 | 
			
		||||
            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 {
 | 
			
		||||
                'type': 'ir.actions.act_window',
 | 
			
		||||
                'res_model': 'account.move',
 | 
			
		||||
| 
						 | 
				
			
			@ -139,8 +134,6 @@ class ResPartner(models.Model):
 | 
			
		|||
                  '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):
 | 
			
		||||
| 
						 | 
				
			
			@ -150,9 +143,10 @@ class ResPartner(models.Model):
 | 
			
		|||
                'partner_id': self.id,
 | 
			
		||||
                '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"),
 | 
			
		||||
                #'journal_id': self.env.user.company_id.deposit_journal_id.id,
 | 
			
		||||
                '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)
 | 
			
		||||
            views = [(self.env.ref('sale.view_order_form').id, 'form')]
 | 
			
		||||
| 
						 | 
				
			
			@ -170,4 +164,3 @@ class ResPartner(models.Model):
 | 
			
		|||
            else:
 | 
			
		||||
                msg += "Todavía no se ha realizado ninguna liquidación de ventas a éste proveedor."
 | 
			
		||||
            raise ValidationError(msg)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,12 +1,12 @@
 | 
			
		|||
# Copyright 2021 Criptomart
 | 
			
		||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
 | 
			
		||||
 | 
			
		||||
#import logging
 | 
			
		||||
import logging
 | 
			
		||||
 | 
			
		||||
from odoo import api, models, fields
 | 
			
		||||
from odoo.exceptions import ValidationError
 | 
			
		||||
 | 
			
		||||
#_logger = logging.getLogger(__name__)
 | 
			
		||||
_logger = logging.getLogger(__name__)
 | 
			
		||||
 | 
			
		||||
class PickingType(models.Model):
 | 
			
		||||
    _inherit = 'stock.picking.type'
 | 
			
		||||
| 
						 | 
				
			
			@ -22,20 +22,10 @@ class Picking(models.Model):
 | 
			
		|||
 | 
			
		||||
    @api.model
 | 
			
		||||
    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:
 | 
			
		||||
           partner = self.env['res.partner'].browse(vals.get("partner_id"))
 | 
			
		||||
           vals['location_id'] = partner.deposit_sale_location_id.id
 | 
			
		||||
       return super().create(vals)
 | 
			
		||||
 | 
			
		||||
    @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,
 | 
			
		||||
           })
 | 
			
		||||
        pick = super().create(vals)
 | 
			
		||||
        if pick.picking_type_id.is_deposit:
 | 
			
		||||
            pick.change_dest_location()
 | 
			
		||||
        return pick
 | 
			
		||||
 | 
			
		||||
    def change_dest_location(self):
 | 
			
		||||
        if self.picking_type_id.code == 'internal':
 | 
			
		||||
| 
						 | 
				
			
			@ -52,4 +42,3 @@ class Picking(models.Model):
 | 
			
		|||
            self.update({
 | 
			
		||||
                'location_dest_id': self.partner_id.deposit_buy_location_id.id,
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,5 @@
 | 
			
		|||
<?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>
 | 
			
		||||
| 
						 | 
				
			
			@ -16,11 +15,14 @@
 | 
			
		|||
                        <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>
 | 
			
		||||
                        <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>
 | 
			
		||||
            </xpath>
 | 
			
		||||
        </field>
 | 
			
		||||
    </record>
 | 
			
		||||
 | 
			
		||||
</odoo>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,4 @@
 | 
			
		|||
<odoo>
 | 
			
		||||
 | 
			
		||||
    <record id="view_picking_type_form_inherit" model="ir.ui.view">
 | 
			
		||||
        <field name="name">Operation Types inherit</field>
 | 
			
		||||
        <field name="inherit_id" ref="stock.view_picking_type_form" />
 | 
			
		||||
| 
						 | 
				
			
			@ -10,5 +9,4 @@
 | 
			
		|||
            </field>
 | 
			
		||||
        </field>
 | 
			
		||||
    </record>
 | 
			
		||||
 | 
			
		||||
</odoo>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue