Reviewers: ,
Please review this at http://codereview.tryton.org/222003/
Affected files:
M CHANGELOG
M purchase.py
M purchase.xml
Index: CHANGELOG
===================================================================
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,4 @@
+* Add currency on product_supplier
* Add a Function field delivery_date to purchase line
* Purchase date is required only at confirmation
* compute_supply_date returns only one date
Index: purchase.py
===================================================================
--- a/purchase.py
+++ b/purchase.py
@@ -1557,6 +1557,8 @@
for product in self.browse(ids):
res[product.id] = product.cost_price
default_uom = product.default_uom
+ default_currency = (user.company.currency.id if user.company
+ else False)
if not uom:
uom = default_uom
if Transaction().context.get('supplier') and
product.product_suppliers:
@@ -1568,16 +1570,15 @@
price.quantity, uom) <= quantity:
res[product.id] = price.unit_price
default_uom = product.purchase_uom
+ default_currency =
product_supplier.currency.id
break
res[product.id] = uom_obj.compute_price(default_uom,
res[product.id], uom)
- if currency and user.company:
- if user.company.currency.id != currency.id:
- date = Transaction().context.get('purchase_date') or
today
- with Transaction().set_context(date=date):
- res[product.id] = currency_obj.compute(
- user.company.currency.id, res[product.id],
- currency.id, round=False)
+ if currency and default_currency:
+ date = Transaction().context.get('purchase_date') or today
+ with Transaction().set_context(date=date):
+ res[product.id] =
currency_obj.compute(default_currency,
+ res[product.id], currency.id, round=False)
return res
Product()
@@ -1605,14 +1606,52 @@
])
delivery_time = fields.Integer('Delivery Time',
help="In number of days")
+ currency = fields.Many2One('currency.currency', 'Currency',
required=True,
+ ondelete='RESTRICT')
def __init__(self):
super(ProductSupplier, self).__init__()
self._order.insert(0, ('sequence', 'ASC'))
+ def init(self, module_name):
+ cursor = Transaction().cursor
+ table = TableHandler(cursor, self, module_name)
+
+ # Migration from 2.2 new field currency
+ created_currency = table.column_exist('currency')
+
+ super(ProductSupplier, self).init(module_name)
+
+ # Migration from 2.2 fill currency
+ if not created_currency:
+ company_obj = Pool().get('company.company')
+ limit = cursor.IN_MAX
+ cursor.execute('SELECT count(id) FROM "' + self._table + '"')
+ product_supplier_count, = cursor.fetchone()
+ for offset in range(0, product_supplier_count, limit):
+ cursor.execute(cursor.limit_clause(
+ 'SELECT p.id, c.currency '
+ 'FROM "' + self._table + '" AS p '
+ 'INNER JOIN "' + company_obj._table + '" AS c '
+ 'ON p.company = c.id '
+ 'ORDER BY p.id',
+ limit, offset))
+ for product_supplier_id, currency_id in cursor.fetchall():
+ cursor.execute('UPDATE "' + self._table + '" '
+ 'SET currency = %s '
+ 'WHERE id = %s', (currency_id,
product_supplier_id))
+
def default_company(self):
return Transaction().context.get('company') or False
+ def default_currency(self):
+ company_obj = Pool().get('company.company')
+ company = None
+ if Transaction().context.get('company'):
+ company = company_obj.browse(Transaction().context['company'])
+ return company.currency.id
+ return False
+
def compute_supply_date(self, product_supplier, date=None):
'''
Compute the supply date for the Product Supplier at the given date
@@ -1659,14 +1698,6 @@
super(ProductSupplierPrice, self).__init__()
self._order.insert(0, ('quantity', 'ASC'))
- def default_currency(self):
- company_obj = Pool().get('company.company')
- company = None
- if Transaction().context.get('company'):
- company = company_obj.browse(Transaction().context['company'])
- return company.currency.id
- return False
-
ProductSupplierPrice()
Index: purchase.xml
===================================================================
--- a/purchase.xml
+++ b/purchase.xml
@@ -789,6 +789,9 @@
<field name="code"/>
<label name="delivery_time"/>
<field name="delivery_time"/>
+ <newline/>
+ <label name="currency"/>
+ <field name="currency"/>
<field name="prices" colspan="4"/>
</form>
]]>
--
[email protected] mailing list