From 17ba157e670090169b1c0bb49de2eff8817f13a6 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Mon, 18 Jan 2016 00:07:23 +0100 Subject: [PATCH] Add logs in procurement scheduler Add method in account_usability : get fiscal position without partner_id --- account_usability/account.py | 48 +++++++++++++++++++++++++++++++++--- stock_usability/stock.py | 21 ++++++++++++++++ 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/account_usability/account.py b/account_usability/account.py index a69fe76..267bad4 100644 --- a/account_usability/account.py +++ b/account_usability/account.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Account Usability module for Odoo @@ -20,8 +20,7 @@ # ############################################################################## -from openerp import models, fields, api, _ -from openerp.exceptions import Warning as UserError +from openerp import models, fields, api class AccountInvoice(models.Model): @@ -137,3 +136,46 @@ class ResPartner(models.Model): payable_journal_item_count = fields.Integer( compute='_compute_journal_item_count', string="Payable Journal Items", readonly=True) + + +class AccountFiscalPosition(models.Model): + _inherit = 'account.fiscal.position' + + @api.model + def get_fiscal_position_no_partner( + self, company_id=None, vat_subjected=False, country_id=None): + '''This method is inspired by the method get_fiscal_position() + in odoo/addons/account/partner.py : it uses the same algo + but without a real partner. + Returns a recordset of fiscal position, or False''' + domains = [[ + ('auto_apply', '=', True), + ('vat_required', '=', vat_subjected), + ('company_id', '=', company_id)]] + if vat_subjected: + domains += [[ + ('auto_apply', '=', True), + ('vat_required', '=', False), + ('company_id', '=', company_id)]] + + for domain in domains: + if country_id: + fps = self.search( + domain + [('country_id', '=', country_id)], limit=1) + if fps: + return fps[0] + + fps = self.search( + domain + + [('country_group_id.country_ids', '=', country_id)], + limit=1) + if fps: + return fps[0] + + fps = self.search( + domain + + [('country_id', '=', None), ('country_group_id', '=', None)], + limit=1) + if fps: + return fps[0] + return False diff --git a/stock_usability/stock.py b/stock_usability/stock.py index 8bff163..022d83a 100644 --- a/stock_usability/stock.py +++ b/stock_usability/stock.py @@ -22,6 +22,9 @@ from openerp import models, fields import openerp.addons.decimal_precision as dp +import logging + +logger = logging.getLogger(__name__) class StockInventory(models.Model): @@ -88,3 +91,21 @@ class StockMoveOperationLink(models.Model): _inherit = 'stock.move.operation.link' qty = fields.Float(digits=dp.get_precision('Product Unit of Measure')) + + +class ProcurementOrder(models.Model): + _inherit = "procurement.order" + + def _procure_orderpoint_confirm( + self, cr, uid, use_new_cursor=False, company_id=False, + context=None): + logger.info( + 'procurement scheduler: START to create procurements from ' + 'orderpoints') + res = super(ProcurementOrder, self)._procure_orderpoint_confirm( + cr, uid, use_new_cursor=use_new_cursor, company_id=company_id, + context=context) + logger.info( + 'procurement scheduler: END creation of procurements from ' + 'orderpoints') + return res