Commit 3047b718 authored by Jean-Paul Smets's avatar Jean-Paul Smets

conflict solved (force_update missing in YO patch for invoice generation)


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@433 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 88961edb
...@@ -37,6 +37,8 @@ from Products.ERP5Type.XMLMatrix import TempXMLMatrix ...@@ -37,6 +37,8 @@ from Products.ERP5Type.XMLMatrix import TempXMLMatrix
from Products.ERP5.Document.DeliveryCell import DeliveryCell from Products.ERP5.Document.DeliveryCell import DeliveryCell
from Acquisition import Explicit, Implicit from Acquisition import Explicit, Implicit
from Products.PythonScripts.Utility import allow_class from Products.PythonScripts.Utility import allow_class
from Products.ERP5.ERP5Globals import movement_type_list, draft_order_state
from DateTime import DateTime
from zLOG import LOG from zLOG import LOG
...@@ -355,13 +357,67 @@ une liste de mouvements...""" ...@@ -355,13 +357,67 @@ une liste de mouvements..."""
cancel = WorkflowMethod(cancel) cancel = WorkflowMethod(cancel)
security.declareProtected(Permissions.ModifyPortalContent, 'invoice') security.declareProtected(Permissions.ModifyPortalContent, '_invoice')
def invoice(self): def _invoice(self):
""" """
This method is called whenever a packing list is being invoiced This method is called whenever a packing list is being invoiced
""" """
# we create an invoice for this delivery
invoice = WorkflowMethod(invoice) self.activate().buildInvoiceList()
invoice = WorkflowMethod(_invoice, 'invoice')
security.declareProtected(Permissions.ModifyPortalContent, 'buildInvoiceList')
def buildInvoiceList(self):
invoice = self.facture_vente.newContent(portal_type='Sale Invoice Transaction',
source=self.getSource(),
destination=self.getDestination(),
source_section=self.getSourceSection(),
destination_section=self.getDestinationSection(),
incoterm = self.getIncoterm(),
delivery_mode = self.getDeliveryMode(),
description = 'Vente'
)
invoice.setCausalityValue(self) # create causality relation
# Copy specific trade conditions (discount, payment)
order = self.getDefaultCausalityValue() # we only copy a single set of trade conditions
if order is not None :
to_copy=[]
to_copy=order.contentIds(filter={'portal_type':'Remise'})
if len(to_copy)>0 :
copy_data = order.manage_copyObjects(ids=to_copy)
new_id_list = invoice.manage_pasteObjects(copy_data)
# copy some properties from order
for key in ('payment_amount', 'payment_ratio', 'payment_term', 'payment_end_of_month', 'payment_additional_term', 'payment_mode', 'trade_date', 'price_currency', 'destination_administration', 'destination_decision', 'destination_payment', 'source_payment'):
invoice.setProperty(key, order.getProperty(key))
# Define VAT recoverability
if invoice.getDestinationSectionValue().getDefaultAddress().getRegion() in ('Europe/Nord/France',None,'') :
vat_ratio = 0.196
vat_recoverable = 1
else :
vat_ratio = 0
vat_recoverable = 0
# Set start_date
invoice_start_date = self.getTargetStartDate()
invoice.edit(value_added_tax_recoverable = vat_recoverable, value_added_tax_ratio = vat_ratio, start_date = invoice_start_date)
# Add Invoice lines for each resource/variation
movement_list = self.getMovementList()
movement_group = invoice.collectMovement(movement_list)
invoice_line_list = invoice.buildInvoiceLineList(movement_group) # This method should be able to calculate price for each line
# Set local_roles
# what's the gestionaire of this order
user_name = ''
# are we on a sales order or puchase order ?
if order is not None :
if order.getPortalType() == 'Sales Order' :
user_name = order.getSourceAdministrationTitle().replace(' ','_')
elif order.getPortalType() == 'Purchase Order' :
user_name = order.getDestinationAdministrationPersonTitle().replace(' ','_')
# update local_roles
invoice.assign_gestionaire_designe_roles(user_name = user_name)
# Pricing methods # Pricing methods
def _getTotalPrice(self, context): def _getTotalPrice(self, context):
...@@ -502,7 +558,9 @@ une liste de mouvements...""" ...@@ -502,7 +558,9 @@ une liste de mouvements..."""
""" """
for m in self.getMovementList(): for m in self.getMovementList():
if not m.isSimulated(): if not m.isSimulated():
return 0 if m.getQuantity() != 0.0 or m.getTargetQuantity() != 0:
return 0
# else Do we need to create a simulation movement ? XXX probably not
return 1 return 1
security.declareProtected(Permissions.View, 'isDivergent') security.declareProtected(Permissions.View, 'isDivergent')
...@@ -880,24 +938,30 @@ une liste de mouvements...""" ...@@ -880,24 +938,30 @@ une liste de mouvements..."""
# IMPORTANT : delivery cells are automatically created during setVariationCategoryList # IMPORTANT : delivery cells are automatically created during setVariationCategoryList
#LOG('buildInvoiceLineList', 0, "invoice_line.contentValues() = %s" % str(invoice_line.contentValues())) #LOG('buildInvoiceLineList', 0, "invoice_line.contentValues() = %s" % str(invoice_line.contentValues()))
for invoice_cell in invoice_line.contentValues(filter={'portal_type':'Invoice Cell'}): if len(variation_category_list) > 0:
category_list = invoice_cell.getVariationCategoryList() for invoice_cell in invoice_line.contentValues(filter={'portal_type':'Invoice Cell'}):
# XXX getVariationCategoryList does not return the same order as setVariationBaseCategoryList category_list = invoice_cell.getVariationCategoryList()
point = [] # XXX getVariationCategoryList does not return the same order as setVariationBaseCategoryList
for base_category in group.variation_base_category_list: point = []
for category in category_list: for base_category in group.variation_base_category_list:
if category.startswith(base_category + '/'): for category in category_list:
point.append(category) if category.startswith(base_category + '/'):
break point.append(category)
kw_list = {'base_id' : 'movement'} break
cell = apply(group.matrix.getCell, point, kw_list) kw_list = {'base_id' : 'movement'}
#LOG('buildInvoiceLineList', 0, cell = apply(group.matrix.getCell, point, kw_list)
# "point = %s, cell = %s" % (str(point), str(cell)))
if cell is not None:
#LOG('buildInvoiceLineList', 0, #LOG('buildInvoiceLineList', 0,
# "quentity = %s, price = %s" % (str(cell.getQuantity()), str(cell.getPrice()))) # "point = %s, cell = %s" % (str(point), str(cell)))
invoice_cell.edit(quantity = cell.getQuantity(), if cell is not None:
price = cell.getPrice(), #LOG('buildInvoiceLineList', 0,
force_update = 1) # "quentity = %s, price = %s" % (str(cell.getQuantity()), str(cell.getPrice())))
invoice_cell.edit(quantity = cell.getQuantity(),
price = cell.getPrice(),
force_update = 1)
else:
# There is no variation category.
invoice_line.edit(quantity = group.total_quantity,
price = group.total_price,
force_update = 1)
return invoice_line_list return invoice_line_list
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment