<commit_before># -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Addons modules by CLEARCORP S.A.
#    Copyright (C) 2009-TODAY CLEARCORP S.A. (<http://clearcorp.co.cr>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import models, fields, api, _
from openerp.exceptions import Warning
import math
from datetime import date
import time
from datetime import datetime
from dateutil.relativedelta import relativedelta
from openerp.addons.decimal_precision import decimal_precision as dp
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
import pytz
from openerp import SUPERUSER_ID

class SaleOrder(models.Model):
    _inherit = 'sale.order'
    
    issue_ids=fields.One2many('project.issue','sale_order_id')
    task_ids=fields.One2many('project.task','sale_id')
    
class SaleOrderLine(models.Model):
    _inherit = 'sale.order.line'
    @api.constrains('price_unit','purchase_price')
    def _check_price_lines(self):
        for line in self:
            if (line.price_unit<line.purchase_price):
                raise Warning('Price unit must be greater or equal to cost price',['price_unit','purchase_price'])
        return True
class ProjectIssue(models.Model):
    _inherit = 'project.issue'
    @api.v7
    def onchange_stage_id(self, cr, uid, ids, stage_id, context=None):
        timesheet_obj=self.pool.get('hr.analytic.timesheet')
        res=super(ProjectIssue, self).onchange_stage_id(cr, uid, ids, stage_id, context)
        issues=self.browse(cr,uid,ids)
        stage = self.pool['project.task.type'].browse(cr, uid, stage_id, context=context)
        if stage.closed==True:
            for issue in issues:
                if issue.timesheet_ids:
                    timesheet_ids = timesheet_obj.search(cr, uid, [('issue_id','=',issue.id)], context=context, order="date desc, end_time desc")
                    timesheet=timesheet_obj.browse(cr,uid,timesheet_ids)[0]
                    minute, hour = math.modf(timesheet.end_time) 
                    user_pool = self.pool.get('res.users')
                    utc = pytz.timezone('UTC')
                    user = user_pool.browse(cr, SUPERUSER_ID, uid)
                    tz = pytz.timezone(user.partner_id.tz) or pytz.utc
                    date_close = tz.localize(datetime.strptime(timesheet.date+' '+str(int(hour))+':'+str(int(minute*60)),'%Y-%m-%d %H:%M'), is_dst=False) # UTC = no DST
                    date_close = date_close.astimezone(utc)
                    res['value']['date_closed']= date_close
                else:
                    res['value']['date_closed']=fields.datetime.now()
        return res
    @api.v7
    def write(self, cr, uid, ids, vals, context=None):
        issues=self.browse(cr,uid,ids)
        if vals.get('stage_id'):
            type_obj=self.pool.get('project.task.type')
            type_ids=type_obj.search(cr, uid,[('id', '=', vals.get('stage_id'))])
            types=type_obj.browse(cr, uid,type_ids)
            for type in types:
                if type.closed==True:
                    for issue in issues:
                        for backorder in issue.backorder_ids:
                            if backorder.picking_type_id.code=='outgoing':
                                if backorder.state!='done':
                                    raise Warning(_('Pending transfer the backorder: %s' % backorder.name))
                                elif not backorder.delivery_note_id:
                                    raise Warning(_('Pending generate delivery note for backorder: %s' % backorder.name))
                                elif backorder.delivery_note_id.state=='draft':
                                    raise Warning(_('Pending confirm delivery note for backorder: %s' % backorder.name))
                        for expense_line in issue.expense_line_ids:
                            if not expense_line.expense_id.state in ['done','pain']:
                                raise Warning(_('Pending change status to done or paid of expense: %s' % expense_line.expense_id.name))
        return super(ProjectIssue, self).write(cr, uid, ids, vals, context)
   
    expense_line_ids=fields.One2many('hr.expense.line','issue_id')
    sale_order_id=fields.Many2one('sale.order','Sale Order')
    invoice_sale_id=fields.Char(string='Invoice Number',related='sale_order_id.invoice_ids.internal_number')
    invoice_ids=fields.Many2many('account.invoice','account_invoice_project_issue_rel',string='Invoices Numbers')
    
class ResPartner(models.Model):
    _inherit = 'res.partner'
    is_provision=fields.Boolean('Provision Apply')

class AccountAnalyticAccount(models.Model):
    _inherit = 'account.analytic.account'
    def name_get(self, cr, uid, ids, context=None):
        if isinstance(ids, (list, tuple)) and not len(ids):
            return []
        if isinstance(ids, (long, int)):
            ids = [ids]
        reads = self.read(cr, uid, ids, ['name','code',], context=context)
        res = []
        for record in reads:
            name = record['name']
            code=record['code']
            if code:
                name=code + ' '+ name
            res.append((record['id'], name))
        return res
    @api.v7
    def name_search(self,cr,uid,name,args=None, operator='ilike',context=None, limit=100):
        res = super(AccountAnalyticAccount, self).name_search(cr,uid,name, args = args, operator = 'ilike')
        ids=self.search(cr,uid,[('code', operator, name)] + args,limit=limit, context=context)
        res = list(set(res + self.name_get(cr, uid, ids, context=context)))
        return res
    @api.v7
    def create(self,cr, uid, vals, context=None):
        pricelist_obj=self.pool.get('contract.pricelist')
        if 'invoice_partner_type' in vals and vals.get('invoice_partner_type')=='branch' and (vals.get('branch_ids')==False or not 'invoice_partner_type' in vals):
            raise Warning(_('Not branches in contract'))
        res=super(AccountAnalyticAccount, self).create(cr, uid, vals, context=context)
        new_contract=self.browse(cr,uid,res,context)
        if new_contract.template_id:
            for pricelist in new_contract.template_id.pricelist_ids:
                pricelist_obj.copy(cr,uid,pricelist.id,{'contract_id':res})
        
        return res
    @api.v7
    def write(self, cr, uid, ids, vals, context=None):
        pricelist_obj=self.pool.get('contract.pricelist')
        if 'invoice_partner_type' in vals and vals.get('invoice_partner_type')=='branch' and not 'branch_ids' in vals:
            for contract in self.browse(cr,uid,ids,context):
                if not contract.branch_ids:
                    raise Warning(_('Not branches in contract'))
        contract=self.browse(cr,uid,ids,context)
        if 'template_id' in vals and vals.get('template_id'):
            for pricelist in contract.pricelist_ids:
                pricelist_obj.unlink(cr,uid,pricelist.id,context)
                
        res=super(AccountAnalyticAccount, self).write(cr, uid, ids, vals, context)
        if 'template_id' in vals and vals.get('template_id'):
            for pricelist in contract.template_id.pricelist_ids:
                pricelist_obj.copy(cr,uid,pricelist.id,{'contract_id':contract.id})
        return res<commit_msg>[FIX]Fix inherit method write for Account Analytic<commit_after># -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Addons modules by CLEARCORP S.A.
#    Copyright (C) 2009-TODAY CLEARCORP S.A. (<http://clearcorp.co.cr>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import models, fields, api, _
from openerp.exceptions import Warning
import math
from datetime import date
import time
from datetime import datetime
from dateutil.relativedelta import relativedelta
from openerp.addons.decimal_precision import decimal_precision as dp
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
import pytz
from openerp import SUPERUSER_ID

class SaleOrder(models.Model):
    _inherit = 'sale.order'
    
    issue_ids=fields.One2many('project.issue','sale_order_id')
    task_ids=fields.One2many('project.task','sale_id')
    
class SaleOrderLine(models.Model):
    _inherit = 'sale.order.line'
    @api.constrains('price_unit','purchase_price')
    def _check_price_lines(self):
        for line in self:
            if (line.price_unit<line.purchase_price):
                raise Warning('Price unit must be greater or equal to cost price',['price_unit','purchase_price'])
        return True
class ProjectIssue(models.Model):
    _inherit = 'project.issue'
    @api.v7
    def onchange_stage_id(self, cr, uid, ids, stage_id, context=None):
        timesheet_obj=self.pool.get('hr.analytic.timesheet')
        res=super(ProjectIssue, self).onchange_stage_id(cr, uid, ids, stage_id, context)
        issues=self.browse(cr,uid,ids)
        stage = self.pool['project.task.type'].browse(cr, uid, stage_id, context=context)
        if stage.closed==True:
            for issue in issues:
                if issue.timesheet_ids:
                    timesheet_ids = timesheet_obj.search(cr, uid, [('issue_id','=',issue.id)], context=context, order="date desc, end_time desc")
                    timesheet=timesheet_obj.browse(cr,uid,timesheet_ids)[0]
                    minute, hour = math.modf(timesheet.end_time) 
                    user_pool = self.pool.get('res.users')
                    utc = pytz.timezone('UTC')
                    user = user_pool.browse(cr, SUPERUSER_ID, uid)
                    tz = pytz.timezone(user.partner_id.tz) or pytz.utc
                    date_close = tz.localize(datetime.strptime(timesheet.date+' '+str(int(hour))+':'+str(int(minute*60)),'%Y-%m-%d %H:%M'), is_dst=False) # UTC = no DST
                    date_close = date_close.astimezone(utc)
                    res['value']['date_closed']= date_close
                else:
                    res['value']['date_closed']=fields.datetime.now()
        return res
    @api.v7
    def write(self, cr, uid, ids, vals, context=None):
        issues=self.browse(cr,uid,ids)
        if vals.get('stage_id'):
            type_obj=self.pool.get('project.task.type')
            type_ids=type_obj.search(cr, uid,[('id', '=', vals.get('stage_id'))])
            types=type_obj.browse(cr, uid,type_ids)
            for type in types:
                if type.closed==True:
                    for issue in issues:
                        for backorder in issue.backorder_ids:
                            if backorder.picking_type_id.code=='outgoing':
                                if backorder.state!='done':
                                    raise Warning(_('Pending transfer the backorder: %s' % backorder.name))
                                elif not backorder.delivery_note_id:
                                    raise Warning(_('Pending generate delivery note for backorder: %s' % backorder.name))
                                elif backorder.delivery_note_id.state=='draft':
                                    raise Warning(_('Pending confirm delivery note for backorder: %s' % backorder.name))
                        for expense_line in issue.expense_line_ids:
                            if not expense_line.expense_id.state in ['done','pain']:
                                raise Warning(_('Pending change status to done or paid of expense: %s' % expense_line.expense_id.name))
        return super(ProjectIssue, self).write(cr, uid, ids, vals, context)
   
    expense_line_ids=fields.One2many('hr.expense.line','issue_id')
    sale_order_id=fields.Many2one('sale.order','Sale Order')
    invoice_sale_id=fields.Char(string='Invoice Number',related='sale_order_id.invoice_ids.internal_number')
    invoice_ids=fields.Many2many('account.invoice','account_invoice_project_issue_rel',string='Invoices Numbers')
    
class ResPartner(models.Model):
    _inherit = 'res.partner'
    is_provision=fields.Boolean('Provision Apply')

class AccountAnalyticAccount(models.Model):
    _inherit = 'account.analytic.account'
    def name_get(self, cr, uid, ids, context=None):
        if isinstance(ids, (list, tuple)) and not len(ids):
            return []
        if isinstance(ids, (long, int)):
            ids = [ids]
        reads = self.read(cr, uid, ids, ['name','code',], context=context)
        res = []
        for record in reads:
            name = record['name']
            code=record['code']
            if code:
                name=code + ' '+ name
            res.append((record['id'], name))
        return res
    @api.v7
    def name_search(self,cr,uid,name,args=None, operator='ilike',context=None, limit=100):
        res = super(AccountAnalyticAccount, self).name_search(cr,uid,name, args = args, operator = 'ilike')
        ids=self.search(cr,uid,[('code', operator, name)] + args,limit=limit, context=context)
        res = list(set(res + self.name_get(cr, uid, ids, context=context)))
        return res
    @api.v7
    def create(self,cr, uid, vals, context=None):
        pricelist_obj=self.pool.get('contract.pricelist')
        if 'invoice_partner_type' in vals and vals.get('invoice_partner_type')=='branch' and (vals.get('branch_ids')==False or not 'invoice_partner_type' in vals):
            raise Warning(_('Not branches in contract'))
        res=super(AccountAnalyticAccount, self).create(cr, uid, vals, context=context)
        new_contract=self.browse(cr,uid,res,context)
        if new_contract.template_id:
            for pricelist in new_contract.template_id.pricelist_ids:
                pricelist_obj.copy(cr,uid,pricelist.id,{'contract_id':res})
        
        return res
    @api.v7
    def write(self, cr, uid, ids, vals, context=None):
        pricelist_obj=self.pool.get('contract.pricelist')
        if 'invoice_partner_type' in vals and vals.get('invoice_partner_type')=='branch' and not 'branch_ids' in vals:
            for contract in self.browse(cr,uid,ids,context):
                if not contract.branch_ids:
                    raise Warning(_('Not branches in contract'))
        contract=self.browse(cr,uid,ids,context)
        if 'template_id' in vals and vals.get('template_id'):
            for pricelist in contract.pricelist_ids:
                pricelist_obj.unlink(cr,uid,pricelist.id,context)
            res=super(AccountAnalyticAccount, self).write(cr, uid, ids, vals, context)
            for pricelist in contract.template_id.pricelist_ids:
                pricelist_obj.copy(cr,uid,pricelist.id,{'contract_id':contract.id})
            return res
        res=super(AccountAnalyticAccount, self).write(cr, uid, ids, vals, context)
        return res
{'fraction_non_alphanumeric': 0.13050701452128968, 'fraction_numerical': 0.002707359094265321, 'mean_word_length': 2.7243354720439963, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6615380', 'n_tokens_mistral': 4984, 'n_tokens_neox': 4706, 'n_words': 1105}