# Copyright (C) 2021: Criptomart () # @author: Criptomart () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import logging from collections import Counter from odoo import models, fields, api _logger = logging.getLogger(__name__) class ResPartner(models.Model): _inherit = 'res.partner' deposit_sale_accept = fields.Boolean( string='Acepta depósitos de venta', help='Éste cliente acepta nuestro material a depósito', ) deposit_buy_accept = fields.Boolean( string='Acepta depósitos de compra', help='Éste proveedor nos deja material a depósito', ) deposit_sale_location_id = fields.Many2one( comodel_name='stock.location', string='Ubicación de depósito de ventas', help="La ubicación que se usará para gestionar el depósito que dejamos a éste proveedor" ) deposit_buy_location_id = fields.Many2one( comodel_name='stock.location', 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( string='Fecha de la última liquidación de compras', help="Cuándo se realizó la última liquidación de compras con éste proveedor." ) @api.onchange('deposit_sale_accept') def _onchange_deposit_sale_accept(self): if self.deposit_sale_accept and not self.deposit_sale_location_id: new_loc = self.env['stock.location'].create({ 'usage': 'internal', 'name': self.name, 'location_id': self.env.ref('stock_picking_deposito.location_deposit_sale').id }) self.update({ 'deposit_sale_location_id': new_loc }) @api.onchange('deposit_buy_accept') def _onchange_deposit_buy_accept(self): if self.deposit_buy_accept and not self.deposit_buy_location_id: new_loc = self.env['stock.location'].create({ 'usage': 'internal', 'name': self.name, 'location_id': self.env.ref('stock_picking_deposito.location_deposit_buy').id }) self.update({ 'deposit_buy_location_id': new_loc }) def make_liquidation_buy(self): _logger.warning("make_liquidation : %s" %self) 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) move_lines = self.env['stock.move.line'].search(search_vals) product_list = Counter() for mv in move_lines: product_list += {'id': mv.product_id.id, 'qty': mv.qty_done} _logger.warning("product_list : %s" %product_list)