From 255eea5655a7d2c75bd3642903d4a804f472f59f Mon Sep 17 00:00:00 2001
From: Fabien Pinckaers <fp@tinyerp.com>
Date: Sun, 17 Oct 2010 18:42:26 +0200
Subject: [PATCH] fix

bzr revid: fp@tinyerp.com-20101017164226-dg8yx79q0c7yrvbr
---
 addons/account/account.py                     |  8 ++++
 addons/account/account_view.xml               | 33 +++++++-------
 addons/account/data/account_data2.xml         |  5 +++
 addons/account/invoice.py                     |  6 ++-
 addons/hr_timesheet/hr_timesheet_data.xml     |  5 +++
 .../hr_timesheet_invoice.py                   |  4 +-
 .../hr_timesheet_invoice_data.xml             | 10 +++++
 addons/profile_tools/installer.py             |  3 +-
 addons/profile_tools/misc_tools_installer.xml |  1 +
 addons/project/installer.py                   |  5 ---
 addons/project_timesheet/project_timesheet.py | 20 +++++++--
 .../project_timesheet_view.xml                |  6 +--
 addons/sale/sale_view.xml                     | 43 +++++++++++--------
 addons/sale/stock_view.xml                    |  2 +-
 .../sale/wizard/sale_make_invoice_advance.py  |  8 ++--
 .../sale/wizard/sale_make_invoice_advance.xml |  2 +-
 16 files changed, 105 insertions(+), 56 deletions(-)

diff --git a/addons/account/account.py b/addons/account/account.py
index bdd6b37b9888..5794c59ffdcb 100644
--- a/addons/account/account.py
+++ b/addons/account/account.py
@@ -2544,9 +2544,17 @@ class wizard_multi_charts_accounts(osv.osv_memory):
         if ids:
             return ids[0]
         return False
+
+    def _get_default_accounts(self, cr, uid, context=None):
+        accounts = [{'acc_name':'Current','account_type':'bank'},
+                    {'acc_name':'Deposit','account_type':'bank'},
+                    {'acc_name':'Cash','account_type':'cash'}]
+        return accounts
+
     _defaults = {
         'company_id': lambda self, cr, uid, c: self.pool.get('res.users').browse(cr, uid, [uid], c)[0].company_id.id,
         'chart_template_id': _get_chart,
+        'bank_accounts_id': _get_default_accounts,
         'code_digits': 6,
         'seq_journal': True
     }
diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml
index cc44e4563d80..8217522715e5 100644
--- a/addons/account/account_view.xml
+++ b/addons/account/account_view.xml
@@ -2413,23 +2413,22 @@
                           <attribute name='string'></attribute>
                   </xpath>
                 <group string="res_config_contents" position="replace">
-                  <field name="company_id" widget="selection"/>
-                  <field name ="code_digits" />
-                  <field name="chart_template_id" widget="selection"/>
-                  <field name ="seq_journal" />
-                  <field colspan="4" mode="tree" name="bank_accounts_id"
-                         nolabel="1" widget="one2many_list">
-                    <form string="Bank Information">
-                      <field name="acc_name"/>
-                      <field name="account_type"/>
-                      <field name="currency_id" widget="selection"/>
-                    </form>
-                    <tree editable="bottom" string="Bank Information">
-                      <field name="acc_name"/>
-                      <field name="account_type"/>
-                      <field name="currency_id" widget="selection"/>
-                    </tree>
-                  </field>
+                    <field name="company_id" widget="selection"/>
+                    <field name ="code_digits" groups="base.group_extended"/>
+                    <field name="chart_template_id" widget="selection"/>
+                    <field name ="seq_journal" groups="base.group_extended"/>
+                    <field colspan="4" mode="tree" name="bank_accounts_id" nolabel="1" widget="one2many_list">
+                        <form string="Bank Information">
+                            <field name="acc_name"/>
+                            <field name="account_type"/>
+                            <field name="currency_id" widget="selection" groups="base.group_extended"/>
+                        </form>
+                        <tree editable="bottom" string="Bank Information">
+                            <field name="acc_name"/>
+                            <field name="account_type"/>
+                            <field name="currency_id" widget="selection" groups="base.group_extended"/>
+                        </tree>
+                    </field>
                 </group>
               </data>
             </field>
diff --git a/addons/account/data/account_data2.xml b/addons/account/data/account_data2.xml
index 8cd2071f70ec..38bdd4b2b2c3 100644
--- a/addons/account/data/account_data2.xml
+++ b/addons/account/data/account_data2.xml
@@ -2,6 +2,11 @@
 <openerp>
     <data noupdate="1">
 
+        <record id="analytic_journal_sale" model="account.analytic.journal">
+            <field name="name">Sales</field>
+            <field name="type">sale</field>
+        </record>
+
         <!--
         Payment term
         -->
diff --git a/addons/account/invoice.py b/addons/account/invoice.py
index a39e259681e6..4b308c064180 100644
--- a/addons/account/invoice.py
+++ b/addons/account/invoice.py
@@ -677,7 +677,7 @@ class account_invoice(osv.osv):
         return (ref or '').replace('/','')
 
     def _get_analytic_lines(self, cr, uid, id):
-        inv = self.browse(cr, uid, [id])[0]
+        inv = self.browse(cr, uid, id)
         cur_obj = self.pool.get('res.currency')
 
         company_currency = inv.company_id.currency_id.id
@@ -693,6 +693,8 @@ class account_invoice(osv.osv):
                     ref = inv.reference
                 else:
                     ref = self._convert_ref(cr, uid, inv.number)
+                if not inv.journal_id.analytic_journal_id:
+                    raise osv.except_osv(_('No Analytic Journal !'),_("You have to define an analytic journal on the '%s' journal!") % (inv.journal_id.name,))
                 il['analytic_lines'] = [(0,0, {
                     'name': il['name'],
                     'date': inv['date_invoice'],
@@ -702,7 +704,7 @@ class account_invoice(osv.osv):
                     'product_id': il['product_id'],
                     'product_uom_id': il['uos_id'],
                     'general_account_id': il['account_id'],
-                    'journal_id': self._get_journal_analytic(cr, uid, inv.type),
+                    'journal_id': inv.journal_id.analytic_journal_id.id,
                     'ref': ref,
                 })]
         return iml
diff --git a/addons/hr_timesheet/hr_timesheet_data.xml b/addons/hr_timesheet/hr_timesheet_data.xml
index e7cb3d5e0d4e..a19b2c672917 100644
--- a/addons/hr_timesheet/hr_timesheet_data.xml
+++ b/addons/hr_timesheet/hr_timesheet_data.xml
@@ -18,5 +18,10 @@
             <field eval="False" name="purchase_ok"/>
         </record>
 
+        <record id="hr.employee" model="hr.employee">
+            <field name="product_id" ref="product_consultant"/>
+            <field name="journal_id" ref="analytic_journal"/>
+        </record>
+
     </data>
 </openerp>
diff --git a/addons/hr_timesheet_invoice/hr_timesheet_invoice.py b/addons/hr_timesheet_invoice/hr_timesheet_invoice.py
index f605fd760bea..8dd25ef1eb3a 100644
--- a/addons/hr_timesheet_invoice/hr_timesheet_invoice.py
+++ b/addons/hr_timesheet_invoice/hr_timesheet_invoice.py
@@ -27,8 +27,8 @@ class hr_timesheet_invoice_factor(osv.osv):
     _name = "hr_timesheet_invoice.factor"
     _description = "Invoice Rate"
     _columns = {
-        'name': fields.char('Internal name', size=128, required=True),
-        'customer_name': fields.char('Name', size=128, help="Name of the customer"),
+        'name': fields.char('Internal name', size=128, required=True, translate=True),
+        'customer_name': fields.char('Name', size=128, help="Label for the customer"),
         'factor': fields.float('Discount (%)', required=True, help="Discount in percentage"),
     }
     _defaults = {
diff --git a/addons/hr_timesheet_invoice/hr_timesheet_invoice_data.xml b/addons/hr_timesheet_invoice/hr_timesheet_invoice_data.xml
index a81af0788b6a..462888e0b392 100644
--- a/addons/hr_timesheet_invoice/hr_timesheet_invoice_data.xml
+++ b/addons/hr_timesheet_invoice/hr_timesheet_invoice_data.xml
@@ -6,5 +6,15 @@
             <field name="customer_name">100%</field>
             <field name="factor">0.0</field>
         </record>
+        <record id="timesheet_invoice_factor2" model="hr_timesheet_invoice.factor">
+            <field name="name">90%</field>
+            <field name="customer_name">90%</field>
+            <field name="factor">10.0</field>
+        </record>
+        <record id="timesheet_invoice_factor3" model="hr_timesheet_invoice.factor">
+            <field name="name">50%</field>
+            <field name="customer_name">50%</field>
+            <field name="factor">50.0</field>
+        </record>
     </data>
 </openerp>
diff --git a/addons/profile_tools/installer.py b/addons/profile_tools/installer.py
index 54fd06028021..6ea024aebbe2 100644
--- a/addons/profile_tools/installer.py
+++ b/addons/profile_tools/installer.py
@@ -29,9 +29,10 @@ class misc_tools_installer(osv.osv_memory):
         'subscription':fields.boolean('Recurring Documents',help='Helps to generate automatically recurring documents.'),
         'survey':fields.boolean('Survey',help='Allows you to organize surveys.'),
         'idea':fields.boolean('Ideas Box',help='Promote ideas of the employees, votes and discussion on best ideas.'),
+        'share':fields.boolean('Share Data / Portals',help='This module allows you to easily give restricted access of any filtered list of objects to any customer or supplier.' \
+            'Just click on the share icon to give access to your customers on their project\'s tasks, support requests, invoices, etc.'),
     }
     _defaults = {
-        'lunch': True,
     }
 misc_tools_installer()
 
diff --git a/addons/profile_tools/misc_tools_installer.xml b/addons/profile_tools/misc_tools_installer.xml
index b59f95ab908e..d81936756a64 100644
--- a/addons/profile_tools/misc_tools_installer.xml
+++ b/addons/profile_tools/misc_tools_installer.xml
@@ -25,6 +25,7 @@
               <attribute name="string">Configure</attribute>
           </xpath>
           <group colspan="8">
+            <field name="share"/>
             <field name="lunch"/>
             <field name="idea"/>
             <field name="survey"/>
diff --git a/addons/project/installer.py b/addons/project/installer.py
index 7a147737768f..693e2d580186 100644
--- a/addons/project/installer.py
+++ b/addons/project/installer.py
@@ -47,11 +47,6 @@ class project_installer(osv.osv_memory):
         'project_gtd': fields.boolean('Getting Things Done',
             help="GTD is a methodology to efficiently organise yourself and your tasks. This module fully integrates GTD principle with OpenERP's project management."),
     }
-
-    _defaults={
-        'project_issue': True,
-    }
-
 project_installer()
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/project_timesheet/project_timesheet.py b/addons/project_timesheet/project_timesheet.py
index f5480793adc2..8d846f919e76 100644
--- a/addons/project_timesheet/project_timesheet.py
+++ b/addons/project_timesheet/project_timesheet.py
@@ -26,6 +26,20 @@ import pooler
 import tools
 from tools.translate import _
 
+class project_project(osv.osv):
+    _inherit = 'project.project'
+    def onchange_partner_id(self, cr, uid, ids, part=False, context=None):
+        result = super(project_project, self).onchange_partner_id(cr, uid, ids, part, context)
+        if result.get('value', False):
+            try:
+                d = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'hr_timesheet_invoice', 'timesheet_invoice_factor1')
+                if d:
+                    result['value']['to_invoice'] = d[1]
+            except ValueError, e:
+                pass
+        return result
+project_project()
+
 class project_work(osv.osv):
     _inherit = "project.task.work"
 
@@ -145,13 +159,13 @@ class project_work(osv.osv):
                     
                 # Compute based on pricetype
                 amount_unit = timesheet_obj.on_change_unit_amount(cr, uid, line_id.id,
-                    prod_id=prod_id,
-                    quantity=vals_line['unit_amount'], unit=False, context=context)
+                    prod_id=prod_id, company_id=False,
+                    unit_amount=vals_line['unit_amount'], unit=False, context=context)
 
                 if amount_unit and 'amount' in amount_unit.get('value',{}):
                     vals_line['amount'] = amount_unit['value']['amount']
 
-            obj.write(cr, uid, [line_id.id], vals_line, context=context)
+            self.pool.get('hr.analytic.timesheet').write(cr, uid, [line_id.id], vals_line, context=context)
             
         return super(project_work,self).write(cr, uid, ids, vals, context)
 
diff --git a/addons/project_timesheet/project_timesheet_view.xml b/addons/project_timesheet/project_timesheet_view.xml
index 05be6d5466ee..c0dcd3a46bc8 100644
--- a/addons/project_timesheet/project_timesheet_view.xml
+++ b/addons/project_timesheet/project_timesheet_view.xml
@@ -27,14 +27,14 @@
             <field name="arch" type="xml">
                 <xpath expr='//filter[@string="Member"]' position='after'>
                     <separator orientation="vertical"/>
-                    <filter icon="terp-camera_test" string="Billable" domain="[('to_invoice','!=', False)]" help="Billable Project"/>
+                    <filter icon="terp-camera_test" string="Invoiceble" domain="[('to_invoice','!=', False)]" help="Invoiceable Project"/>
                 </xpath>
             </field>
         </record>
 
-        <menuitem id="menu_project_billing" name="Billing"
+        <menuitem id="menu_project_billing" name="Invoicing"
                   parent="base.menu_main_pm" sequence="5"/>
-        <menuitem id="menu_project_billing_line" name="Bill Tasks Work"
+        <menuitem id="menu_project_billing_line" name="Invoice Tasks Work"
             parent="menu_project_billing" action="hr_timesheet_invoice.action_hr_analytic_timesheet_open_tree"/>
         <menuitem id="base.menu_project_management_time_tracking" name="Time Tracking"
                 parent="base.menu_main_pm" sequence="5" groups="project.group_project_finance_user"/>
diff --git a/addons/sale/sale_view.xml b/addons/sale/sale_view.xml
index e5357ee0e04b..36ba5e62d816 100644
--- a/addons/sale/sale_view.xml
+++ b/addons/sale/sale_view.xml
@@ -198,7 +198,8 @@
                                 <field name="amount_tax"/>
                                 <field name="amount_total"/>
                                 <button name="button_dummy" states="draft" string="Compute" type="object" icon="gtk-execute"/>
-                                <button name="%(action_view_sale_advance_payment_inv)d" string="Advance Invoice" type="action" icon="gtk-execute" states="draft,manual"/>
+                                <button name="%(action_view_sale_advance_payment_inv)d" string="Advance Invoice"
+                                    type="action" icon="gtk-execute" states="draft,manual" groups="base.group_extended"/>
                             </group>
                             <group col="13" colspan="4">
                                 <field name="state"/>
@@ -374,14 +375,15 @@
                 <form string="Sales Order Lines">
                     <group colspan="4" col="6">
                         <field name="order_id"/>
-                        <field name="product_id" readonly="1"/>
+                        <field name="order_partner_id" readonly="1" invisible="1"/>
                         <field name="invoiced"/>
+
+                        <field name="product_id" readonly="1"/>
                         <field name="product_uom_qty" readonly="1"/>
-                        <field groups="product.group_uos" name="product_uos_qty"/>
                         <field name="product_uom"/>
+
                         <field colspan="4" name="name" groups="base.group_extended"/>
                         <field name="company_id" groups="base.group_multi_company" readonly="1"/>
-                        <field name="order_partner_id" readonly="1" invisible="1"/>
                     </group>
                     <separator colspan="4" string="Price"/>
                     <group colspan="4" col="6">
@@ -394,20 +396,21 @@
                     <separator colspan="4"/>
                     <field name="state"/>
                     <group col="3" colspan="2">
-                       <!-- <button colspan="1"
-                          name="%(action_view_sale_order_line_make_invoice)d"
-                          string="Make Invoice"
-                          type="action"
-                          icon="terp-document-new"
-                          attrs="{'invisible': ['|',('state', 'in', ('draft','cancel')),('invoiced', '=', 1)]}"/>-->
                         <button name="button_cancel"
                             string="Cancel" type="object"
                             icon="gtk-cancel"
-                            attrs="{'invisible': ['|',('state', 'not in', ('confirmed', 'exception')),('invoiced', '=', 1)]}"/>
+                            states="confirmed,exception"/>
+                        <button colspan="1"
+                            name="%(action_view_sale_order_line_make_invoice)d"
+                            string="Create Invoice"
+                            type="action"
+                            states="done"
+                            icon="gtk-go-forward"
+                            attrs="{'invisible': [('invoiced', '=', 1)]}"/>
                         <button name="button_done"
                             string="Done" type="object"
-                            icon="gtk-jump-to"
-                            attrs="{'invisible': ['|',('state', 'not in', ('confirmed','exception')),('invoiced', '=', 0)]}"/>
+                            states="confirmed,exception"
+                            icon="gtk-go-forward" />
                     </group>
                 </form>
             </field>
@@ -444,10 +447,15 @@
             <field name="type">search</field>
             <field name="arch" type="xml">
                 <search string="Search Uninvoiced Lines">
-                    <filter icon="terp-check" string="Confirmed"
+                    <filter icon="terp-check" string="To Do"
                         domain="[('state','=','confirmed')]"
                         name="sale order"
-                        help="Confirmed Sale Order Lines"
+                        help="Confirmed sale order lines, not yet delivered"
+                        />
+                    <filter icon="terp-check" string="Done"
+                        domain="[('state','=','done')]"
+                        name="sale_order_done"
+                        help="Sale order lines done"
                         />
                     <separator orientation="vertical"/>
                     <filter icon="terp-accessories-archiver" string="Shipped"
@@ -514,7 +522,7 @@
         src_model="product.product"
         groups="base.group_extended"/>
 
-        <menuitem id="menu_invoiced" name="Billing" parent="base.menu_base_partner" sequence="5"
+        <menuitem id="menu_invoiced" name="Invoicing" parent="base.menu_base_partner" sequence="5"
             groups="base.group_extended"/>
         <menuitem action="action_order_line_tree2" id="menu_invoicing_sales_order_lines" parent="menu_invoiced" sequence="2" groups="base.group_sale_salesman,base.group_sale_manager"/>
         <!-- configartion view -->
@@ -530,8 +538,7 @@
                   <attribute name="string">Sales Application Configuration</attribute>
                 </form>
                 <separator string="title" position="attributes">
-                <attribute name="string"
-                       >Configure Sales Order Logistic</attribute>
+                <attribute name="string">Configure Sales Order Logistic</attribute>
                   </separator>
                   <xpath expr="//label[@string='description']" position="attributes">
                     <attribute name="string">Setup your sales workflow and default values.</attribute>
diff --git a/addons/sale/stock_view.xml b/addons/sale/stock_view.xml
index ca7506fe5189..4075c523cb9a 100644
--- a/addons/sale/stock_view.xml
+++ b/addons/sale/stock_view.xml
@@ -33,7 +33,6 @@
             res_model="stock.picking"
             src_model="sale.order"
             context="{'contact_display': 'partner'}" />
-        -->
        
        <record id="action_sale_picking_out_tree_view" model="ir.actions.act_window.view">
             <field eval="1" name="sequence"/>
@@ -48,6 +47,7 @@
             <field name="view_id" ref="stock.view_picking_out_form"/>
             <field name="act_window_id" ref="act_sale_order_2_stock_picking"/>
         </record>
+        -->
         
         <!-- Adding Sale Order Reference to outgoing picking -->
         
diff --git a/addons/sale/wizard/sale_make_invoice_advance.py b/addons/sale/wizard/sale_make_invoice_advance.py
index 27c19065652d..0037c10405d3 100644
--- a/addons/sale/wizard/sale_make_invoice_advance.py
+++ b/addons/sale/wizard/sale_make_invoice_advance.py
@@ -26,8 +26,9 @@ class sale_advance_payment_inv(osv.osv_memory):
     _name = "sale.advance.payment.inv"
     _description = "Sale Advance Payment Invoice"
     _columns = {
-        'product_id': fields.many2one('product.product', 'Product', required=True),
-        'amount': fields.float('Unit Price', size=(16, 2), required=True),
+        'product_id': fields.many2one('product.product', 'Advance Product', required=True,
+            help="Select a product of type service which is called 'Advance Product'. You may have to create it and set it as a default value on this field."),
+        'amount': fields.float('Advance Amount', size=(16, 2), required=True, help="The amount to be invoiced in advance."),
         'qtty': fields.float('Quantity', size=(16, 2), required=True),
     }
     _defaults = {
@@ -95,6 +96,7 @@ class sale_advance_payment_inv(osv.osv_memory):
                 }
 
                 inv_id = inv_obj.create(cr, uid, inv)
+                inv_obj.button_reset_taxes(cr, uid, [inv_id], context=context)
 
                 for inv in sale.invoice_ids:
                     ids_inv.append(inv.id)
@@ -168,7 +170,7 @@ class sale_open_invoice(osv.osv_memory):
             tree_id = mod_obj._get_id(cr, uid, 'account', 'invoice_tree')
             tree_res = mod_obj.browse(cr, uid, tree_id, context=context).res_id
         return {
-            'name': _('Deposit Invoice'),
+            'name': _('Advance Invoice'),
             'view_type': 'form',
             'view_mode': 'form,tree',
             'res_model': 'account.invoice',
diff --git a/addons/sale/wizard/sale_make_invoice_advance.xml b/addons/sale/wizard/sale_make_invoice_advance.xml
index 33262a5cdd7c..2cdcb9b8c996 100644
--- a/addons/sale/wizard/sale_make_invoice_advance.xml
+++ b/addons/sale/wizard/sale_make_invoice_advance.xml
@@ -40,7 +40,7 @@
                     <separator string="" colspan="4"/>
                     <group colspan="4">
                         <button special="cancel" string="Close" icon="gtk-cancel"/>
-                        <button name="open_invoice" string="Open Invoice" type="object" icon="gtk-open"/>
+                        <button name="open_invoice" string="Open Invoice" type="object" icon="gtk-go-forward"/>
                     </group>
                  </form>
             </field>
-- 
GitLab