提交 43b2eecb 编写于 作者: yujiaming's avatar yujiaming

calc_price更新

上级 9cdfdbef
package cn.ibizlab.businesscentral.core.extensions.service;
import cn.ibizlab.businesscentral.core.odoo_account.domain.Account_account_tag;
import cn.ibizlab.businesscentral.core.odoo_account.domain.Account_fiscal_position;
import cn.ibizlab.businesscentral.core.odoo_account.domain.Account_tax;
import cn.ibizlab.businesscentral.core.odoo_base.domain.Res_company;
import cn.ibizlab.businesscentral.core.odoo_base.domain.Res_currency;
import cn.ibizlab.businesscentral.core.odoo_base.domain.Res_lang;
import cn.ibizlab.businesscentral.core.odoo_base.domain.Res_partner;
import cn.ibizlab.businesscentral.core.odoo_product.domain.Product_product;
......@@ -14,7 +11,6 @@ import cn.ibizlab.businesscentral.core.odoo_product.domain.Product_template;
import cn.ibizlab.businesscentral.core.odoo_purchase.domain.Purchase_order;
import cn.ibizlab.businesscentral.core.odoo_purchase.service.impl.Purchase_order_lineServiceImpl;
import cn.ibizlab.businesscentral.util.dict.StaticDict;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
......@@ -68,260 +64,52 @@ public class Purchase_order_lineExService extends Purchase_order_lineServiceImpl
@Override
@Transactional
public Purchase_order_line calc_price(Purchase_order_line et) {
Map vals = new HashMap();
Purchase_order order = purchaseOrderService.get(et.getOrderId());
vals.put("price_unit", et.getPriceUnit());
vals.put("currency_id", order.getCurrencyId());
vals.put("product_qty", et.getProductQty());
vals.put("product", et.getProductId());
vals.put("partner", order.getPartnerId());
/**
// account.py中的compute_all()方法, 未处理完成
// 单一税的计算
BigDecimal priceUnit = new BigDecimal(et.getPriceUnit());
BigDecimal productQty = new BigDecimal(et.getProductQty());
// 计算price_subtotal, 小计
BigDecimal priceSubTotal = productQty.multiply(priceUnit);
et.setPriceSubtotal(priceSubTotal);
JSONArray jsonArray = JSONArray.parseArray(et.getTaxesId());
Long taxId = jsonArray.getJSONObject(0).getLong("srfkey");
Account_tax accountTax = accountTaxService.get(taxId);
Long companyId = null;
if(accountTax == null){
companyId = et.getCompanyId();
}else {
companyId = accountTax.getCompanyId();
}
// taxes = self.flatten_taxes_hierarchy(), 未处理
List<Account_tax> taxes = null;
Boolean baseExcludedFlag = false;
Boolean includedFlag = false;
for(Account_tax tax : taxes){
if(tax.getPriceInclude()){
includedFlag = true;
}else if(tax.getIncludeBaseAmount()){
baseExcludedFlag = true;
}
if(baseExcludedFlag && includedFlag){
throw new RuntimeException("无法混合任何税收,包括影响基本金额但不包含在价格中的税收。");
}
}
// 处理币种转换时的舍入
Res_company company = resCompanyService.get(companyId);
Long currencyId = null;
if(vals.get("currency_id") == null){
currencyId = company.getCurrencyId();
}
Res_currency currency = resCurrencyService.get(currencyId);
Double prec = currency.getRounding();
Boolean roundTax = true;
if(StringUtils.compare(company.getTaxCalculationRoundingMethod(), StaticDict.RES_COMPANY__TAX_CALCULATION_ROUNDING_METHOD.ROUND_GLOBALLY.getValue()) == 0){
roundTax = false;
}
Boolean roundTotal = true;
// 未处理
// if 'round' in self.env.context:
// round_tax = bool(self.env.context['round'])
// round_total = bool(self.env.context['round'])
if(!roundTax){
prec *= 1e-5;
}
// recompute_base()方法,未定义
// base = round(price_unit * quantity, precision_rounding=prec), round()方法未处理未处理
Double base = 0.0;
Double sign = 1.0;
if(base <= 0.0){
base = -base;
sign = -1.0;
}
Map totalIncludedCheckpoints = new HashMap();
int i = taxes.size() - 1;
Boolean storeIncludedTaxTotal = true;
Double inclFixedAmount, inclPercentAmount, inclDivisionAmount = 0.0;
Map cachedTaxAmounts = new HashMap();
Collections.reverse(taxes);
for(Account_tax tax : taxes){
// tax_repartition_lines = (
// is_refund
// and tax.refund_repartition_line_ids
// or tax.invoice_repartition_line_ids
// ).filtered(lambda x: x.repartition_type == "tax"), 未处理
List<Long> taxRepartitionLines = null;
// sum_repartition_factor = sum(tax_repartition_lines.mapped("factor"))
Double sumRepartitionFactor = 0.0;
if(tax.getIncludeBaseAmount()){
// base = recompute_base(base, incl_fixed_amount, incl_percent_amount, incl_division_amount, prec) , 未处理
base = null;
inclFixedAmount = inclPercentAmount = inclDivisionAmount = 0.0;
storeIncludedTaxTotal = true;
}
// if tax.price_include or self._context.get('force_price_include'), 未处理
if(tax.getPriceInclude() || ){
if(StringUtils.compare(tax.getAmountType(), StaticDict.ACCOUNT_TAX__AMOUNT_TYPE.PERCENT.getValue()) == 0){
inclPercentAmount += tax.getAmount() * sumRepartitionFactor;
}else if(StringUtils.compare(tax.getAmountType(), StaticDict.ACCOUNT_TAX__AMOUNT_TYPE.DIVISION.getValue()) == 0){
inclDivisionAmount += tax.getAmount() * sumRepartitionFactor;
}else if(StringUtils.compare(tax.getAmountType(), StaticDict.ACCOUNT_TAX__AMOUNT_TYPE.FIXED.getValue()) == 0){
inclFixedAmount += tax.getAmount() * sumRepartitionFactor;
}else{
// tax._compute_amount(base, sign * price_unit, quantity, product, partner) * sum_repartition_factor ,未处理
Double taxAmount = 0.0;
inclFixedAmount += taxAmount;
cachedTaxAmounts.put(i, taxAmount);
}
Boolean condition = StringUtils.compare(tax.getAmountType(), StaticDict.ACCOUNT_TAX__AMOUNT_TYPE.PERCENT.getValue()) != 0 && StringUtils.compare(tax.getAmountType(), StaticDict.ACCOUNT_TAX__AMOUNT_TYPE.DIVISION.getValue()) != 0 && StringUtils.compare(tax.getAmountType(), StaticDict.ACCOUNT_TAX__AMOUNT_TYPE.FIXED.getValue()) != 0;
if(storeIncludedTaxTotal && (tax.getAmount()!=null || condition)){
totalIncludedCheckpoints.put(i, base);
storeIncludedTaxTotal =false;
}
}
i -= 1;
}
// total_excluded = recompute_base(base, incl_fixed_amount, incl_percent_amount, incl_division_amount, prec), 未处理
// 计算不包含税的总计
Double totalExculded = 0.0;
base = totalExculded;
Double totalIncluded = totalExculded;
Double totalVoid = totalExculded;
List<Map> taxesVals = new ArrayList<>();
i = 0;
Double cumulatedTaxIncludedAmount = 0.0;
// 计算price_tax,税率
Double priceTax = null;
// 固定税
if(StringUtils.compare(accountTax.getAmountType(), StaticDict.ACCOUNT_TAX__AMOUNT_TYPE.FIXED.getValue()) == 0){
//
for(Account_tax tax : taxes){
// tax_repartition_lines = (is_refund and tax.refund_repartition_line_ids or tax.invoice_repartition_line_ids).filtered(lambda x: x.repartition_type == 'tax')
List<Long> taxRepartitionLines = null;
// sum_repartition_factor = sum(tax_repartition_lines.mapped('factor'))
Double sumRepartitionFactor = null;
// price_include = self._context.get('force_price_include', tax.price_include)
Double priceInclude = null;
// 计算taxAmount
Double taxAmount = null;
if(priceInclude != null && totalIncludedCheckpoints.get(i) != null){
taxAmount = (Double)totalIncludedCheckpoints.get(i) - (base + cumulatedTaxIncludedAmount);
cumulatedTaxIncludedAmount = 0.0;
}else {
// tax_amount = tax.with_context(force_price_include=False)._compute_amount(base, sign * price_unit, quantity, product, partner)
// taxAmount = ;
}
// tax_amount = round(tax_amount, precision_rounding=prec)
// 对taxAmount进行四舍五入操作
// factorized_tax_amount = round(tax_amount * sum_repartition_factor, precision_rounding=prec)
Double factorizedTaxAmount = null;
if(priceInclude != null && totalIncludedCheckpoints.get(i) == null) {
// cumulated_tax_included_amount += factorized_tax_amount
cumulatedTaxIncludedAmount += factorizedTaxAmount;
}
// subsequent_taxes = self.env['account.tax']
List<Account_tax> subsequentTaxes = null;
// subsequent_tags = self.env['account.account.tag']
List<Account_account_tag> subsequentTags = null;
if(tax.getIncludeBaseAmount() != null){
// 未处理
// subsequent_taxes = taxes[i+1:]
// subsequent_tags = subsequent_taxes.get_tax_tags(is_refund, 'base')
}
// repartition_line_amounts = [round(tax_amount * line.factor, precision_rounding=prec) for line in tax_repartition_lines]
List repartitionLineAmounts = null;
// total_rounding_error = round(factorized_tax_amount - sum(repartition_line_amounts), precision_rounding=prec)
Double totalRoundingError = null;
// nber_rounding_steps = int(abs(total_rounding_error / currency.rounding))
Integer nberRoundingSteps = (int)Math.abs(totalRoundingError / currency.getRounding());
// rounding_error = round(nber_rounding_steps and total_rounding_error / nber_rounding_steps or 0.0, precision_rounding=prec)
Double roundingError = null;
// for repartition_line, line_amount in zip(tax_repartition_lines, repartition_line_amounts)
for(){
if(nberRoundingSteps != null){
// line_amount += rounding_error
nberRoundingSteps -= 1;
}
Map taxInfo = new HashMap();
taxInfo.put("id", tax.getId());
// partner and tax.with_context(lang=partner.lang).name or tax.name, 未处理
String name = tax.getName();
taxInfo.put("name", name);
// sign * line_amount, 未处理
Double amount = sign * 1;
taxInfo.put("amount", amount);
// round(sign * base, precision_rounding=prec), 未处理
base = null;
taxInfo.put("base", base);
taxInfo.put("sequence", tax.getSequence());
// repartition_line.account_id.id, 未处理
Long accountId = null;
if(StringUtils.compare(tax.getTaxExigibility(), StaticDict.ACCOUNT_TAX__TAX_EXIGIBILITY.ON_PAYMENT.getValue()) == 0){
// tax.cash_basis_transition_account_id.id, 不存在?
accountId = tax.g;
}
taxInfo.put("account_id", accountId);
taxInfo.put("analytic", tax.getAnalytic());
taxInfo.put("price_include", priceInclude);
taxInfo.put("tax_exigibility", tax.getTaxExigibility());
// taxInfo.put("tax_repartition_line_id", );
// taxInfo.put("tag_ids", );
// taxInfo.put("tax_ids", );
taxesVals.add(taxInfo);
// if not repartition_line.account_id:
if(){
// total_void += line_amount
totalVoid += 0;
}
priceTax = accountTax.getAmount() * productQty.doubleValue();
}
// 价格中是否已经含税
Boolean priceInclude = accountTax.getPriceInclude();
// 价格不含税,税的类型为价格百分比
if(StringUtils.compare(accountTax.getAmountType(), StaticDict.ACCOUNT_TAX__AMOUNT_TYPE.PERCENT.getValue()) == 0 && !priceInclude){
priceTax = priceSubTotal.doubleValue() * accountTax.getAmount() / 100;
}
// 价格含税,税的类型为价格百分比
if(StringUtils.compare(accountTax.getAmountType(), StaticDict.ACCOUNT_TAX__AMOUNT_TYPE.PERCENT.getValue()) == 0 && priceInclude){
priceTax = priceSubTotal.doubleValue() - (priceSubTotal.doubleValue() / (1 + accountTax.getAmount() / 100));
}
// 价格不含税,税的类型为含税价格百分比
if(StringUtils.compare(accountTax.getAmountType(), StaticDict.ACCOUNT_TAX__AMOUNT_TYPE.DIVISION.getValue()) == 0 && priceInclude){
if((1-accountTax.getAmount()/100) > 0){
priceTax = priceSubTotal.doubleValue() / (1 - accountTax.getAmount() / 100) - priceSubTotal.doubleValue();
}else{
priceTax = 0.0;
}
if(tax.getIncludeBaseAmount() != null){
base += factorizedTaxAmount;
}
totalIncluded += factorizedTaxAmount;
i += 1;
// 价格含税,税的类型为含税价格百分比
if(StringUtils.compare(accountTax.getAmountType(), StaticDict.ACCOUNT_TAX__AMOUNT_TYPE.DIVISION.getValue()) == 0 && priceInclude){
priceTax = priceSubTotal.doubleValue() - (priceSubTotal.doubleValue() * (accountTax.getAmount() / 100));
}
Map result = new HashMap();
// result.put("base_tags", );
result.put("taxes", taxesVals);
result.put("total_excluded", totalExculded);
result.put("total_included", totalIncluded);
result.put("total_void", totalVoid);
*/
// 计算price_subtotal, 小计
BigDecimal priceSubTotal = new BigDecimal(et.getPriceUnit() * et.getProductQty());
et.setPriceSubtotal(priceSubTotal);
// 计算price_tax,税率
Double priceTax = 0.10 * et.getPriceUnit() * et.getProductQty();
et.setPriceTax(priceTax);
// 计算price_total, 总计
BigDecimal priceTotal = priceSubTotal.add(new BigDecimal(priceTax));
et.setPriceTotal(priceTotal);
// this.update(et);
return super.calc_price(et);
}
/**
......@@ -358,24 +146,26 @@ public class Purchase_order_lineExService extends Purchase_order_lineServiceImpl
et.setName(name);
// 计算taxid _compute_tax_id
//
Purchase_order order = purchaseOrderService.get(et.getOrderId());
Long fpos = null;
if (order.getFiscalPositionId() != null) {
fpos = order.getFiscalPositionId();
}else{
// line.order_id.partner_id.with_context(force_company=line.company_id.id).property_account_position_id, 未处理
Res_partner partner1 = resPartnerService.get(order.getPartnerId());
List<Account_fiscal_position> accountFiscalPositions = accountFiscalPositionService.selectByCompanyId(et.getCompanyId());
}
// 获取当前产品的默认税种
JSONArray jsonArray = new JSONArray();
List<Product_supplier_taxes_rel> productSupplierTaxesRels = productSupplierTaxesRelService.selectByProdId(productTemplate.getId());
// List<Account_tax> taxes = new ArrayList<>();
if(productSupplierTaxesRels.size() != 0){
for(Product_supplier_taxes_rel productSupplierTaxesRel : productSupplierTaxesRels){
Account_tax accountTax = accountTaxService.get(productSupplierTaxesRel.getTaxId());
if(accountTax.getCompanyId() != order.getCompanyId()){
productSupplierTaxesRels.remove(productSupplierTaxesRel);
}else{
// taxes.add(accountTax);
JSONObject jsonObject = new JSONObject();
jsonObject.put("srfkey", accountTax.getId());
jsonObject.put("srfmajortext", accountTax.getName());
......@@ -385,7 +175,7 @@ public class Purchase_order_lineExService extends Purchase_order_lineServiceImpl
}
if(fpos != null){
// 调用map_tax()方法, 未处理
et.setTaxesId("test");
et.setTaxesId("");
}else{
et.setTaxesId(jsonArray.toString());
}
......@@ -424,7 +214,7 @@ public class Purchase_order_lineExService extends Purchase_order_lineServiceImpl
Map params = new HashMap();
params.put("order_id", et.getOrderId());
Long seller = null;
// 未处理,需要调用product.py中的_select_seller()方法'
// 未处理,需要调用产品模块中的_select_seller()方法'
Product_supplierinfo supplierinfo = supplierinfoService.get(seller);
// 判断需不需要重新设置计划日期
......@@ -483,9 +273,8 @@ public class Purchase_order_lineExService extends Purchase_order_lineServiceImpl
et.setPriceUnit(priceUnit);
}
// this.create(et);
// 计算税前和税后的总价
et = this.calc_price(et);
// et = this.calc_price(et);
}
return super.product_change(et);
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册